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
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).
In my case JBoss 7EAP required the ejb-jar.xml config file on the war to load the @Startup EJB .
<jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
version="3.1">
<enterprise-beans>...</enterprise-beans></jboss:ejb-jar>
The Startup annotation is for usage with Singleton beans, not with stateless beans. See the javadoc.
Also, @LocalBean is not needed in this case. This declares that you want an additional no-interface view, but this is only needed if the bean implements a remote or local business interface. If you omit it you get a no-interface view by default.
http://docs.oracle.com/javaee/6/api/javax/ejb/Startup.html
Mark a singleton bean for eager initialization during the application startup sequence.