【发布时间】:2012-02-17 22:41:38
【问题描述】:
我有一个拦截器绑定,它是参数化的:
@InterceptorBinding
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface Traced {
@Nonbinding
boolean traceFull() default true;
}
然后我定义一个拦截器实现
@Interceptor
@Traced
public class TracingInterceptor implements Serializable { ... }
在实现中,我想检查将哪个值设置为 traceFull 参数。 (我不想实现真假空三种拦截器实现)
所以我的实现会检查被拦截方法的Interceptor-Binding-Annotation:
Traced traceAnnotation = context.getMethod().getAnnotation(Traced.class);
if (traceAnnotation != null && traceAnnotation.traceFull()) { ... }
这很好用,但如果我使用 Stereotype 或嵌套拦截器绑定,那么我不会得到该方法的 @Traced annotatopn 并且我无法检查设置的值。
所以我的问题是:如何在我的拦截器实现中获得“调用”绑定?
【问题讨论】:
标签: jakarta-ee cdi interceptor