문제

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 ?

도움이 되었습니까?

해결책

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

다른 팁

From this blog post:

Only recently, with the CDI 1.1 version; may 2013 (Java EE 7); you have the possibility to receive a CDI event when the container is ready.

public class CDIStartup {
    public void postConstruct(@Observes @Initialized(ApplicationScoped.class) Object o) {
        // CDI Ready    
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top