Startup bean not called

前端 未结 4 1573
情深已故
情深已故 2021-02-09 21:00

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         


        
相关标签:
4条回答
  • 2021-02-09 21:04

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

    0 讨论(0)
  • 2021-02-09 21:19

    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>
    
    0 讨论(0)
  • 2021-02-09 21:28

    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.

    0 讨论(0)
  • 2021-02-09 21:29

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

    Mark a singleton bean for eager initialization during the application startup sequence.

    0 讨论(0)
提交回复
热议问题