Bir CDI interceptor yazmak istiyorum. Açıklama, ek açıklama yalnızca 1 parametresi içeriyorsa, ancak 2 parametre kullanılıyorsa kırılıyorsa iyi çalışır. Soru neden?Java EE CDI Interceptor ek açıklama parametresi olduğunda çalışmaz
önleme sınıfı:
@Monitored
@Interceptor
@Priority(APPLICATION)
public class MonitoringInterceptor {
@AroundInvoke
public Object logInvocation(InvocationContext ctx) throws Exception {
LOGGER.error("METHOD CALLED!!!"); //this is not called when annotation has 2 parameters
return ctx.proceed();
}
}
açıklama:
@InterceptorBinding
@Target({TYPE, METHOD})
@Retention(RUNTIME)
@Inherited
public @interface Monitored {
public String layer() default "BUSINESS";
public String useCase() default "N/A";
}
Şimdi ilginç kısmı:
@Stateless
public class MyBean {
//this does not work, why?
@Monitored(layer = "BUSINESS", useCase = "test")
//if I use the following annotation it works well
//@Monitored(layer = "BUSINESS")
public String sayHello(String message) {
return message;
}
}
Ben MyBean
@Interceptors
ile açıklamalı olmadığını biliyoruz. Bu amaçlanmıştır. önleme beans.xml
buyuruldu ki:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
<interceptors>
<class>my.package.MonitoringInterceptor</class>
</interceptors>
</beans>
Çalıştığınız parametrelere '@ Nonbinding 'ekledikten sonra teşekkür ederiz. – flash