@Inject, @EJB, @Local, @Remote, @LocalBean, etc… : confused?

前端 未结 2 1150
遇见更好的自我
遇见更好的自我 2020-12-24 07:06

I have the following configuration:

  • 1 EAR on one GF containing 2 EJB-JARs with EJB components.
  • 1 WAR on another Glassfish server (=> other JVM)
2条回答
  •  被撕碎了的回忆
    2020-12-24 07:37

    @Inject annotation is used for java beans(POJOs) while @EJB annotation is used for enterprise java beans. When a container inject an ejb provided by @EJB annotation to another bean it also controls that ejb's lifecycle, performs pooling for stateless beans and so on(when bean which is going to be injected is not deployed the reference will be null). If you use @Inject annotation CDI mechanism simply find and create an instance of injected resource like with new operator(if the implementation of interface which is going to be injected doesn't exist the reference will be null). You can use qualifiers with @Inject annotation to choose different implementation of injected interface.

提交回复
热议问题