JavaEE Tip #3 - PostConstruct

The @PostConstruct annotation makes it possible to run initialization code just before something (EJB, JSF managed bean, CDI bean) is put into service.

In code

    public void init() {
        // put your initialization code here.

Note the the method annotated with @PostConstruct runs only once! So if you are exposing a session bean that gets passivated and subsequently activated this code is NOT run again.

Posted December 12, 2014