我是JSF的新手,我正在尝试创建一个安排简单任务的方法。我使用注释" Schedule"创建了下面的任务。从ejb 3.2开始,我用注释" ApplicationScoped"创建了托管bean。 每次启动我的服务器时,构建器都会运行并打印该行,但带注释的方法不起作用。 我使用的是JSF 2.0,Tomcat 8.0
package br.ifsp.eBlueCard.bean
import java.util.List;
import javax.ejb.Schedule;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import br.ifsp.eBlueCard.entities.ECard;
import br.ifsp.eBlueCard.repository.ECardRepository;
@ManagedBean(eager=true)
@ApplicationScoped
public class TimerEmailBean {
private List<ECard> ecards;
public TimerEmailBean(){
System.out.println("I'm alive.");
}
@Schedule(second="*", minute="*", hour="*")
public void listaECards(){
System.out.println("Hi, me too.");
/*EntityManagerFactory factory = Persistence.createEntityManagerFactory("eBlueCard");
EntityManager manager = factory.createEntityManager();
ECardRepository ecr = new ECardRepository(manager);
try{
this.ecards = ecr.buscaEcardsAtivos();
}catch(Exception e){
System.out.println("VAZIO");
}
if(this.ecards.size() > 0){
for(int i=0;i<ecards.size();i++){
System.out.println(this.ecards.get(i).getCliente().getNome());
}
}else{
System.out.println("VAZIO");
}*/
}
public List<ECard> getEcards() {
return ecards;
}
public void setEcards(List<ECard> ecards) {
this.ecards = ecards;
}
}