Can i configure the Spring MVC application so that when ever i run the application, the controller or any method should be called automatically


I have developed a spring application with rest controller which will have only one GET method. Can i configure the Spring MVC application so that when ever i run the application, the controller or any method should be called automatically with out hitting the api from browser(Just like stand alone application)



You can create a bean that implements org.springframework.boot.CommandLineRunner interface.

E.g.

As this is a regular Spring component, you can use field or constructor injection to inject other Spring components.

https://stackoverflow.com/questions/64371317/can-i-configure-the-spring-mvc-application-so-that-when-ever-i-run-the-applicati