Spring boot 运行在不同模块中配置的Spring计划作业
我有一个Spring启动应用程序,我使用Spring调度来调度cron作业。我的应用程序中有3个不同的模块:服务工具A、服务工具B和服务应用程序 我的服务应用程序模块具有Spring引导配置和应用程序类,如下所示:Spring boot 运行在不同模块中配置的Spring计划作业,spring-boot,spring-scheduled,Spring Boot,Spring Scheduled,我有一个Spring启动应用程序,我使用Spring调度来调度cron作业。我的应用程序中有3个不同的模块:服务工具A、服务工具B和服务应用程序 我的服务应用程序模块具有Spring引导配置和应用程序类,如下所示: package com.service.tool.main; @SpringBootApplication @ComponentScan("com.service.tool") @EnableAsync @EnableScheduling public class Applica
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);
}
}
@Scheduled(fixedRate = 4000)
public void printName() {
System.out.println("Hello World");
}
现在我在其他模块service toolA和service toolB中有了预定的作业。我将其配置如下:
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);
}
}
@Scheduled(fixedRate = 4000)
public void printName() {
System.out.println("Hello World");
}
但是,当我运行应用程序时,计划的作业不会启动。当我将这些预定方法放置在应用程序类所在的服务应用程序模块中时,它们就会运行
如何在不同的模块和服务应用程序模块中运行它?将具有
printName()
的类的包添加到扫描的包列表中,例如:
@ComponentScan("com.service.tool","com.service.module1")
还是一样的问题。它不起作用。不确定是否需要为调度程序注册bean。