javaee:尝试通过带有多个值的注释绑定拦截器
我在向JavaEE7应用程序添加参数化日志拦截器时遇到了一个奇怪的问题 我从使用@Interceptors注释的类拦截器开始编写自定义拦截器绑定。我所没有的看起来像这样 注释javaee:尝试通过带有多个值的注释绑定拦截器,java,logging,binding,interceptor,Java,Logging,Binding,Interceptor,我在向JavaEE7应用程序添加参数化日志拦截器时遇到了一个奇怪的问题 我从使用@Interceptors注释的类拦截器开始编写自定义拦截器绑定。我所没有的看起来像这样 注释 @Inherited @InterceptorBinding @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.TYPE, ElementType.METHOD }) public @interface LogMethodCa
@Inherited
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({
ElementType.TYPE,
ElementType.METHOD
})
public @interface LogMethodCall {
MethodLogger logLevel() default MethodLogger.INFO;
}
拦截器
@Slf4j
@LogMethodCall
@Interceptor
@Priority(Interceptor.Priority.APPLICATION)
public class ActionInterceptor {
@AroundInvoke
protected Object protocolInvocation(final InvocationContext ic) throws Exception {
log.info(
"{}: <{}> called. Parameters={}",
ic.getTarget().getClass().getName(),
ic.getMethod().getName(),
ic.getParameters());
return ic.proceed();
}
}
当我像这样使用它时,一切正常
当我尝试使用时购买更改日志级别并使用
@LogMethodCall(logLevel=MethodLogger.DEBUG)
然后我的截取器就再也不会被调用了
我错过了什么?为什么设置注释值会破坏代码?如果你说你的拦截器只在值为信息时才捕获,你可以考虑把你的代码> LogOrthor()/<代码>属性设为“非绑定”。 默认情况下,将bean限定符与注入点限定符匹配时考虑限定符参数。匹配时不考虑@Nonbinding参数 试试这个:
@Inherited
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({
ElementType.TYPE,
ElementType.METHOD
})
public @interface LogMethodCall {
@Nonbinding MethodLogger logLevel() default MethodLogger.INFO;
}
有没有不设置默认值的方法?
@Inherited
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({
ElementType.TYPE,
ElementType.METHOD
})
public @interface LogMethodCall {
@Nonbinding MethodLogger logLevel() default MethodLogger.INFO;
}