zoukankan      html  css  js  c++  java
  • spring context 继承

    <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,反之不能。

  • 相关阅读:
    2017第5周五随想录~改变活法
    2017第5周四
    《高绩效教练》笔记
    2017第5周二杭州印象
    2017第5周一
    代码自动生成工具_java版
    20个代码生成框架
    通过数据库表自动生成POJO(JavaBean)对象
    java工具类–自动将数据库表生成javabean
    Nginx+Tomcat+Memcached负载均衡集群服务搭建
  • 原文地址:https://www.cnblogs.com/allenwas3/p/9089861.html
Copyright © 2011-2022 走看看