EJB 3.1 @EJB Injection into POJO

前端 未结 4 1319
清歌不尽
清歌不尽 2020-12-05 08:22

With the new EJB 3.1 spec is it possible to inject an EJB into a pojo? I know in EJB 3.0 the @EJB annotation could be used to inject an EJB but this did not work on simple

4条回答
  •  遥遥无期
    2020-12-05 09:02

    With the new EJB 3.1 spec is it possible to inject an EJB into a pojo? I know in EJB 3.0 the @EJB annotation could be used to inject an EJB but this did not work on simple pojos.

    Injection of EJB into an POJO is possible IF you use JSR-299 (Java Contexts and Dependency Injection) i.e. if your POJO is a CDI managed bean. In that case, you could do:

    @Inject MyEJB service
    

    But this is not an EJB 3.1 feature, this comes from CDI. And if you're not using CDI, you'll have to do a lookup.

提交回复
热议问题