Controlling CDI Startup inside EJB 3.1

半腔热情 提交于 2019-12-05 09:55:10

After much research I found some help from the guys in IBM, since we are working with WebSphere Application Server I can just add a JVM Property called:

"com.ibm.ws.cdi.immediate.ejb.start" = true

to the WAS in the Admin console, and he will make sure that once I will get to the EJB @PostConstruct method in the @Startup bean I created the CDI Container will already be up and running and already injected.

It Works!!

Here is the link to the Problem and Solution in IBM site:

http://www-01.ibm.com/support/docview.wss?uid=swg1PM62774

Maybe double check that CDI is in fact enabled in all places of the application where it needs to be. Try adding this code to BaseStartupLoader as an experiment:

@Singleton
@Startup
public class BaseStartupLoader {

    @Inject @MyStartup
    BaseStartUp myStartup;

    @Inject
    private InjectionTest test;


    public static class InjectionTest {}
}

If the test variable comes up null in the @PostConstruct, then CDI is likely not enabled in the jar where BaseStartupLoader is declared.

If say, for example, BaseStartupLoader is declared in a jar called orange.jar and MyStartUpLoader is declared in a jar called yellow.jar, then both these files must exist:

  • orange.jar!/META-INF/beans.xml
  • yellow.jar!/META-INF/beans.xml

If CDI is properly enabled in both jars via a META-INF/beans.xml, then this is a bug in the container. All @Inject points are required to be completed (for CDI-enabled jars), prior to @PostConstruct being called. This is true regardless of if @Startup is used and one of the beans happens to be an EJB.

Take a look at DeltaSpike. There's a CDI Control module that should do what you're looking for now. I believe Java EE 7 should fix this as well.

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