Java EE – 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.");
    }
}

However, the code is not called after the application is deployed What caused this?

Solution

Try the following annotation set:

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

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

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>