我已经写了一个调度器,这是如预期的工作只与xml文件。但是我不能用Javaconfig类来运行它。以下是代码。
调度程序:
public class DemoServiceBasicUsageCron {
@Scheduled(cron="*/5 * * * * ?")
public void demoServiceMethod()
{
System.out.println("Method executed at every 5 seconds. Current time is :: "+ new Date());
}}Java配置:
@Configuration
public class TestCron {
@Bean
public DemoServiceBasicUsageCron demoCron() {
System.out.println(" bean created ");
return new DemoServiceBasicUsageCron();
}}我将配置文件读为
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestCron.class);
}需要任何建议,它可以工作。
致敬Sai
发布于 2016-08-13 13:30:45
在TestCron类中添加@EnableScheduling注释。
https://stackoverflow.com/questions/38928980
复制相似问题