Search code examples
servletsjakarta-eeejbservletcontextlistener

EJB and ServletContextListener initialization


I have a war with a class extending ServletContextListener and have override the contextInitialized method.

I also have a Stateless EJB that is using data from my ContextListener on initialization. The problem is that I think sometimes the container chooses to initialize my EJB first then the ContextListener, and that of course results in some NullPointers exceptions. Is there some way to tell the container to initialize my ContextListener first and then my EJBs?


Solution

  • Are the EJB and the web application separate applications ? If yes you can control the deployment order as documented here

    If they are part of the same enterprise application this weblogic documentation suggests that it should be as simple as changing the order of the ejbs and your web application in application.xml