zoukankan      html  css  js  c++  java
  • [Spring] ClassPathXmlApplicationContext类

    1. 该类在package org.springframework.context.support包下. 该包在4.0.1中封装在spring-context-***.jar中.

    其无参构造函数的文档注释:

    * Create a new ClassPathXmlApplicationContext, loading the definitions
    * from the given XML file and automatically refreshing the context.

    就是为了bean风格的配置, 创建一个新的 ClassPathXmlApplicationContext 实例.

    其参数是String 类型的配置路径(configLocations),对应的重载方法支持多个String类型的配置路径参数.

    配置路径可以通过 AbstractRefreshableConfigApplicationContext.getConfigLocations()获取.

    配置路径可以使具体的文件如: "/myfiles/context.xml"

    或者 Ant-style 样式,如: "/myfiles/*-context.xml"

      (see the AntPathMatcher javadoc for pattern details).

    为了避免路径重复,后面的bean定义会覆盖前面的同名bean定义.

    -----------------构造函数---------------------

    ClassPathXmlApplicationContext(java.lang.String configLocation)

    Create a new ClassPathXmlApplicationContext, loading the definitions from the given XML file and automatically refreshing the context.
    ------------------方法--------------------------
    Modifier and TypeMethod and Description
    protected Resource[] getConfigResources()
    Return an array of Resource objects, referring to the XML bean definition files that this context should be built with.

     继承自抽象类AbstractApplicationContext的方法.getBean() (重载多次)

    =======================例子==============================


    即使测试类没有调用userDao和UserServiceImpl.

    但还是调用了set方法.

    因为再创建cxt时,已经将ApplicationContext.xml中的bean注入了.

    bean中的property中的name属性,对应的是bean中该类中的set方法.

    如:

        <bean id="p1" class="entity.Person">
            <property name="nameX" value="zz"></property>
            <property name="content" value="I Like You"></property>
        </bean>

    control+左键 点卡nameX,会跳转到setNameX上:

    和其形参name和类的属性名name无关.

    只需要保持这两者一致,即可.

      

    宛如智障,暗藏锋芒
  • 相关阅读:
    4、numpy——创建数组
    3、NumPy 数组属性
    2、NumPy 数据类型
    windos常见命令操作
    PHP操作MongoDB学习笔记
    MongoDB(八)Mongodb——GridFS存储
    MongoDB(七)MongoDb数据结构
    MongoDB(五)mongo语法和mysql语法对比学习
    MongoDB可视化工具RoboMongo----Windows安装 1
    MongoDB(四)mongodb设置用户访问权限
  • 原文地址:https://www.cnblogs.com/zienzir/p/9111224.html
Copyright © 2011-2022 走看看