【发布时间】:2015-09-03 00:41:53
【问题描述】:
我有一个问题。每当我们有 EJB jars 时
<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 Bean。我怎样才能获得它?
【问题讨论】:
-
我不认为有一种声明性的方式来做到这一点 - 有充分的理由,因为“所有 bean”在 CDI 世界中是一个相当模糊的概念。即使在部署时间之后,Bean 也会来来去去。本文描述了一种以编程方式对向管理器注册的所有 bean 执行此操作的方法,这可能会为您提供所需的结果:byteslounge.com/tutorials/…。未经测试,这里没有我自己的东西,所以我不得不留下它作为评论。
-
完美的灵魂。谢谢!
标签: java jakarta-ee java-ee-6 java-melody