injectionPoint.getBean() returns null if bean is an EJB bean in Java EE 7 (CDI 1.1)

扶醉桌前 提交于 2019-12-03 07:55:09

Using

injectionPoint.getMember().getDeclaringClass()

works for me in WildFly 10.1.0 and I also quickly tested it in Payara Server 4.1.1.162 #badassfish (build 116). I also did a test on brand new Payara Server 4.1.1.164 #badassfish (build 28). However,I had to change the scope of the producer bean to @ApplicationScoped. Default scope did not work. In my case, it even makes sense :)

The

injectionPoint.getBean().getBeanClass()

method worked for me in the old Payara, but not in the new WildFly 10.1.0.Final and new Payara Server 4.1.1.164 #badassfish (build 28).

If you have a look at Payara, the current new version 164 contains Weld 2.4.0.Final and WildFly 10.1.0Final uses version 2.3.5.Final. In both versions, the classical code does not work !

The conclusion is, on older CDI implementations (Weld), it works. In some newer Weld (introduced in Payara 161), the behavior changed. I do not know if this is intentional or not.

However, the solution is to use

injectionPoint.getMember().getDeclaringClass()

and annotate the producer bean with

@javax.enterprise.context.ApplicationScoped

annotation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!