Servlet的Spring root WebApplicationContext

Pau*_*zie 5 java spring spring-mvc

我有一个使用SpringMVC DispatcherServlet加载WebApplicationContext的webapp.Spring参考文档:

"每个DispatcherServlet都有自己的WebApplicationContext,它继承了根WebApplicationContext中已经定义的所有bean .这些继承的bean可以在特定于servlet的范围内重写,并且可以为给定的servlet实例定义新的特定于范围的bean.

但是我在哪里放置这个根WebApplicationContext?

Jon*_*man 9

我们applicationContext.xmlWEB-INF目录中,该配置中的bean可用于spring-servlet.xml配置,其定义使用

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)

顺便说一下ContextLoaderListener,它负责管理根上下文

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)