Startup bean not called

Rogach picture Rogach · Jul 25, 2011 · Viewed 8.8k times · Source

I created a Java Web Application Project in NetBeans, and created a startup bean in it:

package malibu.util;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;

@Stateless
@LocalBean
@javax.ejb.Startup
public class Startup {
    @EJB
    private ProviderEJB providerEJB;

    @PostConstruct
    public void onStartup() {
        System.err.println("Initialization success.");
    }
}

But the code is not called after I deploy the application. What can cause this?

Answer

Tomasz Nurkiewicz picture Tomasz Nurkiewicz · Jul 25, 2011

Try the following set of annotations:

@Singleton
@Startup
public class Startup {
    @EJB
    private ProviderEJB providerEJB;

    @PostConstruct
    public void onStartup() {
        System.err.println("Initialization success.");
    }
}

You will find more details here and in this book (chapter 2).