【发布时间】:2019-03-27 07:06:34
【问题描述】:
我创建了一个 Spring Boot 应用程序来实现 Quartz 调度程序。在 Job 类中,我想使用 application.properties 中的一些属性。如何注入?
当我尝试使用值注释来使用它时,得到 null。
这是我的代码
主类:
@SpringBootApplication
public class SchedulerApplication {
public static void main(String[] args) {
SpringApplication.run(SchedulerApplication.class, args);
}
@Bean
public Scheduler scheduler() {
Scheduler scheduler = null;
try {
SchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
scheduler = stdSchedulerFactory.getScheduler();
scheduler.start();
} catch (SchedulerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return scheduler;
}
}
职位类别:
@Component
public class ScheduleJob implements org.quartz.Job {
@Value("${ijobs.service.url}")
public String ijobsUrl;
public ScheduleJob() {
}
public void execute(JobExecutionContext context) throws JobExecutionException {
String jobName = null;
System.out.println("ijobsUrl--->"+ijobsUrl);
}
}
【问题讨论】:
标签: spring spring-boot properties quartz-scheduler quartz