Servlet的Spring root WebApplicationContext
我有一个使用SpringMVC DispatcherServlet加载WebApplicationContext的webapp。 Spring参考文档说 :
“每个DispatcherServlet都有自己的WebApplicationContext,它inheritance了根WebApplicationContext中已经定义的所有bean。这些inheritance的bean可以在特定于servlet的范围内被覆盖,并且您可以为给定的servlet实例定义新的特定于范围的bean。
但是我在哪里放置这个根WebApplicationContext?
我们在WEB-INF
目录中有applicationContext.xml
,并且该配置中的bean可用于spring-servlet.xml
配置,其定义使用
contextConfigLocation /WEB-INF/applicationContext.xml
顺便说一句,它的ContextLoaderListener
负责管理根上下文
org.springframework.web.context.ContextLoaderListener