【发布时间】:2018-11-21 11:31:06
【问题描述】:
我想要一个 Guice 拦截器来拦截对带注释的类或带注释的方法的调用。我希望能够将两者结合起来,即。用具有不同属性的方法注解覆盖类注解。
我的工作是这样的:
// Intercept all METHODS annotated with @MyAnnotation
bindInterceptor(
Matchers.any(),
Matchers.annotatedWith(company.MyAnnotation),
new TracingInterceptor());
// Intercept all methods in CLASSES annotated with @MyAnnotation
bindInterceptor(
Matchers.annotatedWith(company.MyAnnotation),
Matchers.any(),
new TracingInterceptor());
但是,当我这样注释类时:
@MyAnnotation
class MyClass {
@MyAnnotation
public void myMethod() {}
}
拦截器被调用了两次,这很糟糕!
有什么办法可以避免两次触发拦截器,但行为相同?
【问题讨论】:
标签: aop guice interceptor