CDI: Using Interceptors across different modules / bean archives

前端 未结 6 577
[愿得一人]
[愿得一人] 2021-02-05 11:18

My Java EE 6 application consists of a war and an ejb module packaged in ear file. I\'m using CDI for DI (i.e. I have a beans.xml file in both modules). I want to use a logging

6条回答
  •  耶瑟儿~
    2021-02-05 12:09

    J2EE 7 specification says (reference):

    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.

    An Example:

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

提交回复
热议问题