我编写了一个调度程序,它只与 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);
}
需要它可以工作的任何建议。
问候赛