I developed a web application in spring and observed that beans are loading two times while starting the server.
Please let me know why is this behaviour and advise if there is anything wrong in configuration.
I understand that on providing the load-on-startup as 1, the beans will be loaded during context loading. But, why does the same beans load even when application war file is deployed? Currently, I see the beans loading twice during context initialization and then when the WAR file is getting deployed.
Here is my web.xml
<servlet>
<servlet-name>PizzaRest</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
com.pizza.resource,
com.pizza
</param-value>
</init-param>
<init-param>
<param-name>jersey.config.disableMoxyJson.server</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>pizzaservlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:pizza-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>PizzaRest</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>pizzaservlet</servlet-name>
<url-pattern>/pizzaservlet/*</url-pattern>
</servlet-mapping>
While loading the server, I see beans are loading twice.
Jun 10, 2015 8:49:27 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 746 ms
INFO: Loading XML bean definitions from class path resource [pizza-context.xml]
Jun 10, 2015 8:49:36 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 460 ms
INFO: Loading XML bean definitions from class path resource [servlet-context.xml]