且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CDI:跨不同模块/ bean归档使用拦截器

更新时间:2023-12-03 17:37:28

J2EE 7规范说(参考):

J2EE 7 specification says (reference):


拦截器您在beans.xml文件中指定的内容仅适用于同一归档中的
类。使用@Priority注释为包含多个
模块的应用程序全局指定
拦截器

The interceptors that you specify in the beans.xml file apply only to classes in the same archive. Use the @Priority annotation to specify interceptors globally for an application that consists of multiple modules

此解决方案具有独立于供应商的优势。

This solution has the advantage of being vendor independent.

示例:

@Logged
@Interceptor
@Priority(Interceptor.Priority.APPLICATION)
public class LoggedInterceptor implements Serializable { ... }