@Scheduled与Javaconfig不兼容
问题描述:
我写了一个调度程序,它只按照预期的方式使用xml文件。但是我无法用Javaconfig类来运行它。以下是代码。@Scheduled与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);
}
需要哪些它可以工作的任何建议。
问候 西
答
加入TestCron类@EnableScheduling注解。
Thanks @abaghel。它工作正常。 – abc