My understanding of a basic Java application is that every application should have a main() method but when I wrote a Spring MVC application (not Spring Boot), I don't think there was ever a main() method that I wrote. Isn't it mandatory? What am I missing here? Or is this implemented in Spring somewhere internally? If yes, where is the main defined?
A Spring Boot application's main class is a class that contains a public static void main() method that starts up the Spring ApplicationContext. By default, if the main class isn't explicitly specified, Spring will search for one in the classpath at compile time and fail to start if none or multiple of them are found.
Yeah, you don't need it. You can just remove it if it is only ever just a WAR file you are building.
@Configuration. Treat as the configuration file for Spring MVC-enabled applications. Also, we use the @Bean tag to register ViewResolver. We use InternalResourceViewResolver.
A Spring MVC is a Java framework which is used to build web applications. It follows the Model-View-Controller design pattern. It implements all the basic features of a core spring framework like Inversion of Control, Dependency Injection.
Spring MVC is just a Servlet based framework which can only be run inside Servlet container like Tomcat or Webligic. The main method is deep in Servlet container that when you start will go and load war file into Java VM and delegate HTTP calls made to it to the appropriate Servlet that in turn will delegate to your Spring controller. For example when you run Tomcat startup.bat or startup.sh scripts they eventually will run Java main method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With