我配置了一个自定义注解, 在我本机加上注解的类会被拦截,可是部署到服务器上就不能生效,感觉像方法未被拦截一样?
注解是这样的
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface ContentStatic {
/**
* 是否静态化
*
* @return
*/
boolean isStatic() default true;
/**
* 是否异步执行,默认为true
*
* @return true,如果需要异步执行
*/
boolean async() default true;
}
注解的配置类是这样的
public class ContentStaticAopConfigration
extends SimpleAopMaker<ContentStatic> {
private static final Log log = Logs.get();
@Override
public List<? extends MethodInterceptor> makeIt(ContentStatic contentStatic,
Method method, Ioc ioc) {
log.error("---ContentStaticAopConfigration init---");
return Arrays.asList(
new ContentStaticAopInterceptor(ioc, contentStatic, method));
}
}
这个方法加载是配置在dao.json中
$aop_scontent : {
type : "com.xxx.aop.ContentStaticAopConfigration"
}
拦截器操作类是
public class ContentStaticAopInterceptor implements MethodInterceptor {
private static final Log log = Logs.get();
protected Ioc ioc;
protected SiteService siteService;
protected boolean isStatic;
protected boolean async;
public ContentStaticAopInterceptor(Ioc ioc, ContentStatic contentStatic,
Method method) {
this.ioc = ioc;
isStatic = contentStatic.isStatic();
async = contentStatic.async();
}
@Override
public void filter(InterceptorChain chain) throws Throwable {
try {
chain.doChain();
}
catch (Throwable e) {
log.error(e);
throw e;
}
finally {
doStatic(chain, null);
}
}
protected void doStatic(InterceptorChain chain, Throwable e)
throws InterruptedException {
if (siteService == null) {
siteService = ioc.get(SiteService.class);
}
try {
log.errorf("---doStatic begin---");
siteService.aopStaticMainSite(async);
log.errorf("---doStatic end---");
}
catch (Exception e1) {
log.error("contentStatic fail", e1);
}
}
}
还有个奇怪的问题是 log.error("---ContentStaticAopConfigration init---");这句话会被打印多次,难道不该在dao.json实例化吗?我以为服务器启动就会打印,结果是第一次请求了上面那个打印才生成,而且是打印多次