Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring root WebApplicationContext for Servlet

I have a webapp that uses SpringMVC DispatcherServlet to load a WebApplicationContext. The Spring reference documentation says:

"each DispatcherServlet has its own WebApplicationContext, which inherits all the beans already defined in the root WebApplicationContext. These inherited beans can be overridden in the servlet-specific scope, and you can define new scope-specific beans local to a given servlet instance.

But where do I put this root WebApplicationContext?

like image 985
Paul McKenzie Avatar asked Aug 19 '10 12:08

Paul McKenzie


1 Answers

We have applicationContext.xml in theWEB-INF directory, and the beans in that config are available to the spring-servlet.xml config, its defined using

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

By the way its the ContextLoaderListener which is responsible for managing the root context

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
like image 193
Jon Freedman Avatar answered Oct 03 '22 23:10

Jon Freedman