Are CDI event observer methods compatible with EJBs?

妖精的绣舞 提交于 2019-12-05 03:39:47

I think this is the answer :

CDI observer methods must apparently either be static or declared in the local interface of an EJB if the EJB declares a local interface. Normally if you try to declare an observer method that isn't in the local interface you get an exception from Weld like this :

org.jboss.weld.exceptions.DefinitionException: WELD-000088 Observer method must be static or local business method:  [method] public org.stain.ObserverBean.testMethod(EventClass) on public@Singleton class org.stain.ObserverBean

For some reason glassfish does not report this exception properly when loading my EAR file and simply says Exception while loading the app.

Adding the method to the local interface (or removing the interface declaration on the class) fixes the problem and allows the application to load normally.

I noticed the same problem with the latest version of weld. But if you add the @LocalBean annotation it will work with @Singleton and @Singleton @Startup.

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