簡體   English   中英

在應用程序范圍的bean上的postconstruct方法上創建Scheduler

[英]Creating Scheduler on postconstruct method on application scoped bean

在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;
    }
}

具有@Startup注釋(在類上)和@Schedule注釋(在方法上)的@Singleton EJB應該足夠。 您不需要使用@PostConstruct因為這將迫使您在某些位置注入Singleton EJB實例(我認為在您的用例中這是不可能的)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM