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.
8
1
@Component
2
public class MyRunner implements CommandLineRunner {
3
@Override
4
public void run(String... args) throws Exception {
5
// Do stuff here at startup
6
}
7
}
8
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
No Comments