this is my job schedule part
and i want to remove the cron trigger, CronTrigger("0 40 13 * * ?") then access the cron expression from application.property.
@Component 公共類 DynamicjobSchedule {
public void schedulejobs() {
for (ConnectionStrings obj : listObj) {
System.out.println("Cron Trigger Starting..");
scheduler.schedule(new DashboardTask(obj), new CronTrigger("0 40 13 * * ?"));
}
}
}
how can i create one property file in src/main.resources location and mention the cron expression then call from the scheduler
uj5u.com熱心網友回復:
最簡單的方法是像這樣使用@Value注釋:
@Component
public class DynamicjobSchedule {
@Value("${name.of.cron.expression.in.application.properties}")
private String cronExpression;
public void schedulejobs() {
for (ConnectionStrings obj : listObj) {
System.out.println("Cron Trigger Starting..");
scheduler.schedule(new DashboardTask(obj), new CronTrigger(cronExpression));
}
}
}
您也可以@Value在方法引數上使用注釋:
@Component
public class DynamicjobSchedule {
public void schedulejobs(@Value("${name.of.cron.expression.in.application.properties}") String cronExpression) {
for (ConnectionStrings obj : listObj) {
System.out.println("Cron Trigger Starting..");
scheduler.schedule(new DashboardTask(obj), new CronTrigger(cronExpression));
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/329754.html
