我有问题。每当我们有EJB罐子CDI豆中的默认拦截器
<ejb-jar
xmlns = "http://java.sun.com/xml/ns/javaee"
version = "3.0"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
>
<interceptors>
<interceptor>
<interceptor-class>net.bull.javamelody.MonitoringInterceptor</interceptor-class>
</interceptor>
</interceptors>
<assembly-descriptor>
<interceptor-binding>
<ejb-name>*</ejb-name>
<interceptor-class>net.bull.javamelody.MonitoringInterceptor</interceptor-class>
</interceptor-binding>
</assembly-descriptor>
</ejb-jar>
现在我MonitoringInterceptor拦截所有EJB。这里有一个问题:我可以用CDI拦截器做类似的事吗?
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<interceptors>
<class>net.bull.javamelody.MonitoringInterceptor</class>
</interceptors>
</beans>
我想有MonitoringInterceptor默认设置为注入应用程序的所有CDI豆。我如何获得这个?预先感谢您的回复。
我不认为有一种声明方式来做到这一点 - 有很好的理由“所有豆类”在CDI世界中是一个相当模糊的概念。即使在部署时间之后,豆类也会来来去去。本文介绍了一种以编程方式为所有注册到管理器的bean执行此操作的方法,这可能会为您提供所需的结果:http://www.byteslounge.com/tutorials/java-ee-add-cdi-interceptor-以编程方式。这里没有经过检验也没有我自己的,所以我不得不将它作为评论。 – Gimby
完美灵魂。谢谢! – ArturSkowronski