1

Do we need to add load on start up value for spring dispatcher servlet?

<servlet>  
    <servlet-name>mvc-dispatcher</servlet-name>  
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup><!-- **THIS** -->
</servlet> 

What is the consequences of not adding this?

premkumar
  • 47
  • 1
  • 11
  • Did you see http://stackoverflow.com/questions/809775/what-does-the-servlet-load-on-startup-value-signify ? –  May 01 '17 at 08:35
  • @RC.Yes I have seen that Question. But My doubt is Even if i dint specify load-on-start-up it will be loaded when first request for the app comes. So i want to know if would miss anything if i dont provide it – premkumar May 01 '17 at 08:53
  • 1
    I guess it's not mandatory - it would just make your first call(s) to a Spring Controller have to wait for initialization to finish. In a cluster environment you might have a large number of calls hitting your webapp once it's deployed and might cause timeouts if Spring is not yet up – Jan May 01 '17 at 09:38

1 Answers1

1

The first controller that should be loaded in spring MVC is the dispatcher servlet, and yes it is important to mention where it is and which controller to load as your dispatcher because you should load it as your first controller.

The dispatcher job is most important with accepting requests from users and passing them to the right controllers, and afterwards, return the views to users.

Moshe Arad
  • 3,587
  • 4
  • 18
  • 33