Search code examples
javacdibootstrapping

Execute code at CDI startup


Is there a simple way to execute code just after CDI has bootstrapped ?

Actually I've got an @ApplicationScopped bean which I want to be instanciated just after CDI has bootstrapped, is there a simple way to do that ?


Solution

  • There's quite a few solutions but to me there's only two that does not feel hacky. I am not sure if Java EE 7 solved this somehow though, could not find anything when I googled.

    1. Use @Startup from EJB. This is best if you can use EJB
    2. Use the Servlet Module from deltaspike with @Observes @Initialized ServletContext context

    http://deltaspike.apache.org/servlet.html