Bean start not called

I created a Java web application project in NetBeans and created a bean run 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 application deployment. What can cause this?

+6
source share
3 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."); } } 

Here you will find more information here and in this book (chapter 2).

+11
source

Startup annotations for use with Singleton beans, not stateless beans. See javadoc .

In addition, @LocalBean is not required in this case. This states that you want an additional view without an interface, but this is only necessary if the bean implements a remote or local business interface. If you omit it, by default you will get a view without an interface.

+6
source

http://docs.oracle.com/javaee/6/api/javax/ejb/Startup.html

Check singleton bean for reliable initialization during application startup sequence.

0
source

Source: https://habr.com/ru/post/893517/


All Articles