代码
@Interceptor(SomeInterceptor.class)
public class SomeClass {
@Interceptor(OtherInterceptor.class)
public Object method1 (Object param) {
return param;
}
public Object method2 (Object param) {
return param;
}
}
问题1
是否在每个方法调用中创建了SomeInterceptor和OtherInterceptor?
问题2
是否可以“设置”Inteceptor类使其成为单例?例如。 SomeInterceptor和OtherInterceptor只创建一次。
答案 0 :(得分:1)
根据CDI规范,每个CDI bean最多应该拦截一个拦截器,并且它的生命周期与bean之一相关联。
因此,如果您的bean是@ApplicationScoped,那么将只有一个'单线'拦截器
还有这个bug in Weld。