在ApplicationScoped bean的PostConstruct方法上创建Scheduler作业是否有效。
@ApplicationScoped
public class myBean {
private String name = "Soup of the day";
@Schedule(hour="0", persistent=false)
@PostConstruct
public void afterCreate() {
System.out.println("Bean Created");
}
public String getName() {
return name;
}
public void setName(String name){
this.name = name;
}
}
答案 0 :(得分:0)
具有@Singleton
注释(在类上)和@Startup
注释(在方法上)的@Schedule
EJB应该足够了。您不需要使用@PostConstruct
,因为这会强制您将Singleton EJB实例注入某些位置(根据您的使用情况,我假设这是不可能的)