Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 730
Rogach Avatar asked Jul 25 '11 18:07

Rogach


1 Answers

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

like image 159
Tomasz Nurkiewicz Avatar answered Sep 23 '22 15:09

Tomasz Nurkiewicz