I have a Spring Boot web application packaged as a WAR file, and I want to be able to run some tasks (scripts or commands) on demand. For instance:
- Initialize Database Schema
- Select database programmatically
- Data transfer, if necessary, for new versions of the application (moving files, database operations, etc.).
- Verifying data integrity between saved files and database content
These “commands” would be much easier to implement if they had access to the same beans (services, DAO) and models as the actual web application. I expect that I need to create a Spring application context somewhere for this to happen. I would also prefer to pack these commands along with the rest of the application so that they are tested with it and easily deployed.
Essentially, I want to know how to achieve something similar to the Laravel artisan (PHP) commands .
I read about running a class inside WAR here and here . I am looking for the "Spring way" for packages and running commands. Should I integrate Spring batch jobs for this? From what I understand, Spring Batch is designed for large workloads that can be shared in multiple batches. Should I bite a bullet and put the commands in a second separate maven module that references the first?
Update
ApplicationRunner ( Stefan!), , , , Spring . , - runner. MVC , . , , , ( ).
2
, Spring CommandLineRunner. beans -, 3 :