Running Scripts in a Sprint Boot Web Application
You can use ApplicationRunner see spring boot application runner. The runners are executed after the app started and you have access to the spring context.
The CommandLineRunner
class is used precisely for this. See also How does a Spring Boot console based application work?