简体   繁体   中英

Startup ejb bean does not work

I am trying to do something at startup using a startup ejb. But my bean is never called.

This is my bean:

import javax.annotation.PostConstruct;
import javax.ejb.Startup;
import javax.inject.Singleton;

@Singleton
@Startup
public class StartupBean {

    @PostConstruct
    public void doSomething(){
        System.out.println("why??");
    }

}

I am using jboss 7.1.1.

What am i doing wrong? You can find my source code at bitbucket: https://bitbucket.org/cremersstijn/jee/src/9e22ed2b798a/simple-startup-bean

You're importing the wrong Singleton. If you want to create a singleton session bean, use javax.ejb.Singleton.

http://docs.oracle.com/javaee/6/api/javax/ejb/Singleton.html vs. http://docs.oracle.com/javaee/6/api/javax/inject/Singleton.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM