Spring Boot - ApplicationRunner and CommandLineRunner
ApplicationRunner and CommandLineRunner interfaces lets you to execute the code after the Spring Boot application is started.
ApplicationRunner
ApplicationRunner interface allows you to run some code after Sprint Boot starts.
MyApplicationRunner.java
1 |
|
CommandLineRunner
CommandLineRunner interface allows you to run some code after Sprint Boot starts. The difference between CommandLineRunner and ApplicationRunner is run() method’s parameter. With CommandLineRunner you get raw unprocessed arguments.
MyCommandListRunner.java
1 |
|
sample output with application argument --foo=bar
:
1 | 2019-05-02 22:59:35.261 INFO 15067 --- [ restartedMain] com.example.demo.MyApplicationRunner : foo |
Reference