Within my Spring boot application
I currently run it using the following:
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan("my.packages.to.scan")
@EnableScheduling
public class Scheduler {
public static void main(String[] args){
SpringApplication.run(Scheduler.class, args);
}
}
This then finds the following class to run:
@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() {
}
}
As can be seen from the above, my application runs all three methods in sequence.
I would like to change my application so any method/task can be run from the command line at any time, rather than calling the main method and running all three methods in a row.
How can I do so? Do I need to move my methods from the MyApplication class?
I would suggest to look into project Spring Batch. That project is exactly for such requirements. Especially this section of its docs may be of your interest. It describes how can be spring batch jobs executed from command line.
Reaction on comment: Here is my Github repository with working example. Notice shell scripts as examples how to execute certain tasks from command line.