You can also load context when defining the servlet itself ( WebApplicationContext )
<servlet> <servlet-name>admin</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/*.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>admin</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
not ( ApplicationContext )
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext*.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>
or can do both together.
The disadvantage of using WebApplicationContext is that it will only load the context for this particular Spring entry point ( DispatcherServlet ), where, as with the above methods, the context for multiple entry points will be loaded (e.g. Webservice Servlet, REST servlet , etc. .).
The context loaded by the ContextLoaderListener will be the parent context for the one that is specifically loaded for the DisplacherServlet. Thus, you can download all your business services, data access or beans repository in the context of the application and select your controller, view the beans converter in WebApplicationContext.
Aniket Thakur Sep 27 '15 at 7:57 2015-09-27 07:57
source share