Meaning of bean discovery mode annotated in CDI 1.1

前端 未结 3 832
不知归路
不知归路 2020-11-30 08:52

I am migrating an application to Java EE 7 and would like to CDI 1.1. But I don\'t get the meaning of bean-discovery-mode=\"annotated\". The CDI 1.1 specificat

3条回答
  •  旧巷少年郎
    2020-11-30 09:09

    I also agree with the answer form @rmuller. But I want to point out that there is still different behavior on application servers Payara and Wildfly. See the following example with a normal not scoped class but having a @EJB injection:

    public class SomeClass  {
        @EJB
        MyService myService;
    
       ...
    }
    

    If you provide a beans.xml file with:

     .... version="1.2" bean-discovery-mode="annotated"....
    

    Payara 4.1 will treat the class SomeClass NOT as a CDI bean and will NOT inject the service EJB. This is clear to me that it behaves as stated in the specification.

    But Wildfly 10 treats the class as an CDI bean and injects the service EJB which is not expected. To get this working the beans.xml file should look like this:

     .... version="1.2" bean-discovery-mode="all"....
    

    It's amazing that the two most common application servers are different here in behavior.

提交回复
热议问题