Question

I have a CDI / Weld application running with Hibernate and JSF 2 inside Jetty.

I need to do some initialization after Jetty server is started. I do it in a @PostConstruct method on an @ApplicationScoped bean, but it is not called until a request is sent to the application. I cannot wait for that.

I tried to find out if there is any way to hook into application lifecycle through Weld, but I could not find anything.

Can anybody help me with this please?

Was it helpful?

Solution 3

To note for whoever might stumble upon this question. I couldn't make it work, and ended up writing my own singletons to deal with situation.

OTHER TIPS

In Java EE 7 / CDI 1.1 / Weld 2.0 you can observe @Initialized(ApplicationScoped.class) ServletContext event. That will cause an instance of your bean to be created eagerly.

What about a servlet context listener? Injection should work fine in those if you need to get to something. It also depends on what kind of initialization you need to do. There may be things you won't be able to get to such as request or conversation scoped beans.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top