Skip to main content

@PostConstruct not being called

2 replies [Last post]
jeremynorris
Offline
Joined: 2010-01-20
Points: 0

Consider the following simple bean:

@ApplicationScoped
public class Foobar {

@PostConstruct
public void initialize() {
...
}

}

When deployed on Glassfish v3, the @javax.annotation.PostConstruct method is not being fired. This bean is working as expected otherwise (so I don't think this is a basic JEE6 configuration issue). Is there something I'm missing about the conditions under which this event is supposed to occur? I thought JSR316 now enabled these lifecycle methods to be fired on any managed bean?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mohamedelshami
Offline
Joined: 2007-07-17
Points: 0

@PostConstruct won't get fired unless the EJB instance get's initiated, this will work on deployment time only if this is a Singleton EJB with @Startup annotation which will force the application server to create instant on the deployment time of this bean.

jeremynorris
Offline
Joined: 2010-01-20
Points: 0

Just to clarify, in the example, this is @javax.enterprise.context.ApplicationScoped (not the JSF one).