@Singleton,@Startup,@PostConstruct在EJB3.1和Glassfishv3.0.1上不起作用 [英] @Singleton, @Startup, @PostConstruct doesn't work on EJB3.1 and Glassfishv3.0.1

查看:578
本文介绍了@Singleton,@Startup,@PostConstruct在EJB3.1和Glassfishv3.0.1上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的 @Singleton @Startup EJB:

  @Singleton 
@Startup
@DependsOn(SchedulerEJB)
public class SchedulerStartUp {

private static Logger log = Logger.getLogger(SchedulerStartUp.class);

@EJB
SchedulerEJB schedEJB;

@PostConstruct
public void atStartup(){
log.info(startUp)
System.out.println(startUp);

schedEJB.cancelTimer(EBlastScheduler);
schedEJB.createTimer(* / 1,*,*);
}
}

SchedulerEJB

  @Stateless 
public class SchedulerEJB {

@Resource
TimerService timerService;

public cancelTimer(String timerInfo){/*...*/}

public createTimer(String sec,String min,String hour){/*...* /}

@Timeout
public void execute(Timer timer){/*...*/}
}

Maven pom:

  //已使用Glassfishv3.0.1和依赖关系的EJB3.1:
< dependency>
< groupId> javax< / groupId>
< artifactId> javaee-api< / artifactId>
< version> 6.0< / version>
< scope>已提供< / scope>
< / dependency>


解决方案

您有无效类型的bean作为属性< a href =http://docs.oracle.com/javaee/6/api/javax/ejb/DependsOn.html =noreferrer> @ DependsOn 。取决于用于表示两个Singleton会话bean之间的依赖关系,而不是在Singleton和Stateless之间。您应该将SchedulerEJB更改为Singleton或删除依赖关系。



如果您决定将SchedulerEJB更改为Singleton,则也不需要@DepensOn,因为(从EJB 3.1规范):注意,如果一个Singleton只需要从其PostConstruct方法调用另一个Singleton
,那么没有明确的排序元数据是
需要。在这种情况下,第一个Singleton将仅使用ejb
引用来调用目标单例。在那里,ebb引用(通过注入或查找)获取
不是
必然意味着实际创建相应的Singleton
bean实例。



I have a problem with this setup and I can't even view the logs.

This is my @Singleton @Startup EJB:

@Singleton
@Startup
@DependsOn("SchedulerEJB")
public class SchedulerStartUp {

    private static Logger log = Logger.getLogger(SchedulerStartUp.class);

    @EJB
    SchedulerEJB schedEJB;  

    @PostConstruct
    public void atStartup() {
       log.info("startUp")
       System.out.println("startUp");

       schedEJB.cancelTimer("EBlastScheduler");
       schedEJB.createTimer("*/1", "*", "*");
    }
}

The SchedulerEJB:

 @Stateless
 public class SchedulerEJB {

    @Resource
    TimerService timerService;         

    public cancelTimer(String timerInfo){/*...*/}

    public createTimer(String sec, String min, String hour) {/*...*/}

    @Timeout
    public void execute(Timer timer) {/*...*/}
 }

Maven pom:

 //Been Using Glassfishv3.0.1 and EJB3.1 with a dependency of:
 <dependency>
     <groupId>javax</groupId>
     <artifactId>javaee-api</artifactId>
     <version>6.0</version>
     <scope>provided</scope>
 </dependency>

解决方案

You have invalid type of bean as an attribute of @DependsOn. DependsOn is for expressing dependency between two Singleton session beans, not between Singleton and Stateless. You should change SchedulerEJB to be Singleton or remove dependency.

If you decide change SchedulerEJB to Singleton, then @DepensOn is also not needed, because (from EJB 3.1 specification):

Note that if one Singleton merely needs to invoke another Singleton from its PostConstruct method, no explicit ordering metadata is required. In that case, the first Singleton would merely use an ejb reference to invoke the target Singleton. There, the acquisition of the ejb reference (either through injection or lookup) does not necessarily imply the actual creation of the corresponding Singleton bean instance.

这篇关于@Singleton,@Startup,@PostConstruct在EJB3.1和Glassfishv3.0.1上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆