0

我编写了一个调度程序,它只与 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);

    }

需要它可以工作的任何建议。

问候赛

4

1 回答 1

1

在 TestCron 类中添加 @EnableScheduling 注解。

于 2016-08-13T05:30:45.253 回答