我编写了一个调度程序,它仅在处理 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);
}
需要任何可行的建议。
问候 赛
最佳答案
在 TestCron 类中添加 @EnableScheduling 注解。
关于java - @Scheduled 不适用于 Javaconfig,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38928980/