2017-08-03 66 views
1

我有一个Spring Boot应用程序,我使用Spring计划安排cron作业。我的应用程序中有3个不同的模块:service-toolA,service-toolB和service-application。运行弹簧在不同模块中配置的计划作业

我的服务的应用模块具有弹簧引导配置和应用程序类,如下所示:

package com.service.tool.main; 

@SpringBootApplication 
@ComponentScan("com.service.tool") 
@EnableAsync 
@EnableScheduling 
public class Application { 

    public static void main(String args[]) { 
     SpringApplication.run(Application.class); 
    } 
} 

现在我有我的计划作业的其他模块服务toolA和服务toolB。我已经配置它们如下:

@Scheduled(fixedRate = 4000) 
public void printName() { 
    System.out.println("Hello World"); 
} 

但是,当我运行该应用程序时,计划作业不会开始。当我将这些Scheduled方法放在应用程序类所在的service-application模块中时,它们会运行。

如何在不同的模块中运行它,并且在服务应用模块中配置该配置?

回答

0

添加包它具有printName()到扫描包的列表类,例如:

@ComponentScan("com.service.tool","com.service.module1") 
+0

仍然是同样的问题。它没有工作。不知道是否需要为Scheduler注册Bean。 – Sri