代码之家  ›  专栏  ›  技术社区  ›  Paul McKenzie

servlet的Spring根WebApplicationContext

  •  4
  • Paul McKenzie  · 技术社区  · 14 年前

    我有一个webapp,它使用SpringMVC DispatcherServlet加载webapplicationContext。弹簧参考文件 says :

    “每个DispatcherServlet都有自己的 WebApplicationContext,它继承 所有的bean都已经在 根webapplicationContext . 这些 继承的bean可以在中重写 servlet特定的范围,以及 可以定义新的范围特定的bean 给定servlet实例的本地。

    但是我应该把这个根webapplicationContext放在哪里呢?

    1 回复  |  直到 14 年前
        1
  •  9
  •   Jon Freedman    14 年前

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

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

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

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>