jakarta-eeejbjava-ee-6ejb-3.1

Startup bean not called


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?


Solution

  • 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).