views:

34

answers:

1

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?

+3  A: 

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>
Jon Freedman