在我的Spring boot application
我用下面的当前运行它:
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan("my.packages.to.scan")
@EnableScheduling
public class Scheduler {
public static void main(String[] args){
SpringApplication.run(Scheduler.class, args);
}
}
然后,找到要运行的以下类:
@Component
public class MyApplication {
@Transactional
@Scheduled(fixedRate = 400000, initialDelay = 1000)
public void tasks() {
methodOne();
methodTwo();
methodThree();
}
public void methodOne() {
}
public void methodTwo() {
}
public void methodthree() {
}
}
从上面可以看出,我的应用程序按顺序运行所有三种方法。
我想更改应用程序,以便可以随时从命令行运行任何方法/任务,而不是调用main方法并连续运行所有三个方法。
我该怎么办?我需要从MyApplication类中移动方法吗?
我建议研究一下Spring Batch项目。该项目正是满足此类要求的。特别是您的文档这一部分可能会引起您的兴趣。它描述了如何从命令行执行spring batch作业。
对评论的反应: 这是我的Github存储库,带有工作示例。注意shell脚本作为示例,说明如何从命令行执行某些任务。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句