首页 > 编程语言 > 详细

spring context 继承

时间:2018-05-25 18:40:39      阅读:200      评论:0      收藏:0      [点我收藏+]
<web-app>
    <display-name>Archetype Created Web Application</display-name>
    
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
  
       <servlet>
        <servlet-name>example</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/servlet-example.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>example</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    
</web-app>

上面的配置文件定义了 2 个 WebApplicationContext,前一个容器的配置文件是 applicationContext.xml, 后一个容器的配置文件是 servlet-example.xml,前者是后者的 parent。

手动创建父子容器:

ClassPathXmlApplicationContext appCtx = 
        new ClassPathXmlApplicationContext("parent.xml");

// 指定父容器
ClassPathXmlApplicationContext childCtx = 
        new ClassPathXmlApplicationContext(new String[]{"child.xml"}, appCtx);

现象:子容器可以获得父容器中的 bean,反之不能。

spring context 继承

原文:https://www.cnblogs.com/allenwas3/p/9089861.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!