Java Spring Boot应用程序:将应用程序拆分为要从命令行运行的独立任务?
在我的Java Spring Boot应用程序:将应用程序拆分为要从命令行运行的独立任务?,java,spring,methods,spring-boot,spring-batch,Java,Spring,Methods,Spring Boot,Spring Batch,在我的Spring引导应用程序中我当前使用以下命令运行它: @SpringBootApplication @EnableAutoConfiguration @ComponentScan("my.packages.to.scan") @EnableScheduling public class Scheduler { public static void main(String[] args){ SpringApplication.run(Scheduler.class
Spring引导应用程序中
我当前使用以下命令运行它:
@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批处理作业 对评论的反应:
. 请注意shell脚本作为如何从命令行执行某些任务的示例。好的,使用java是否有一种简单的方法可以配置我的应用程序,使其能够单独调用每个方法?是的,有!现在看一看JMXIm,你能给出一个我将如何使用它的例子吗?你希望能够在应用程序运行时运行任务,还是在启动它时仅作为命令行上的参数运行?我希望它们能够作为cmd行上的参数运行?