Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

main() method in a spring mvc application

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?

like image 929
p0tta Avatar asked Jun 01 '17 02:06

p0tta


People also ask

Where is main method in spring?

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.

Does spring require main method?

Yeah, you don't need it. You can just remove it if it is only ever just a WAR file you are building.

What is @configuration in Spring MVC?

@Configuration. Treat as the configuration file for Spring MVC-enabled applications. Also, we use the @Bean tag to register ViewResolver. We use InternalResourceViewResolver.

What is Spring MVC with example?

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.


1 Answers

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.

like image 176
tsolakp Avatar answered Sep 25 '22 13:09

tsolakp