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 Type Method 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无关.

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

  

[Spring] ClassPathXmlApplicationContext类的更多相关文章

  1. Spring 创建 IOC 容器 ClassPathXmlApplicationContext 类

    一.ClassPathXmlApplicationContext 类的作用 在 Java 环境中使用 Spring 时,需要用 new ClassPathXmlApplicationContext(c ...

  2. 使用spring配置类代替xml配置文件注册bean类

    spring配置类,即在类上加@Configuration注解,使用这种配置类来注册bean,效果与xml文件是完全一样的,只是创建springIOC容器的方式不同: //通过xml文件创建sprin ...

  3. Spring自定义类扫描器 ClassPathScanningCandidateComponentProvider

    项目中有个需求 读取xml文件,然后 对xml文件进行解析,比如如果是 Gender=0/1的话,分别代表男女. 所以需要在构造函数之后,初始化bean之前进行过滤解析 xml文件: <inte ...

  4. Spring普通类/工具类获取并调用Spring service对象的方法

    参考<Spring普通类获取并调用Spring service方法>,网址:https://blog.csdn.net/jiayi_0803/article/details/6892455 ...

  5. spring 工具类大集合

    接以前的文章 apache-commons 常用工具类 和文章 apache-commons 工具类扩展 小家 Spring 对 spring 的工具类做了详细的介绍(一) 这里我抽出一些好用的类,不 ...

  6. 521我发誓读完本文,再也不会担心Spring配置类问题了

    当大潮退去,才知道谁在裸泳.关注公众号[BAT的乌托邦]开启专栏式学习,拒绝浅尝辄止.本文 https://www.yourbatman.cn 已收录,里面一并有Spring技术栈.MyBatis.中 ...

  7. Spring配置类深度剖析-总结篇(手绘流程图,可白嫖)

    生命太短暂,不要去做一些根本没有人想要的东西.本文已被 https://www.yourbatman.cn 收录,里面一并有Spring技术栈.MyBatis.JVM.中间件等小而美的专栏供以免费学习 ...

  8. Spring同一个类中的注解方法调用AOP失效问题总结

    public interface XxxService { // a -> b void a(); void b(); } @Slf4j public class XxxServiceImpl ...

  9. Spring工具类 非spring管理环境中获取bean及环境配置

    SpringUtils.java import org.springframework.beans.BeansException; import org.springframework.beans.f ...

随机推荐

  1. 永久修改VS include目录

    原文:https://blog.csdn.net/sysprogram/article/details/49214727 VS2008在选项里可以设置全局的Include目录和Lib目录, 但是VS2 ...

  2. (转)Awesome Object Detection

    Awesome Object Detection 2018-08-10 09:30:40 This blog is copied from: https://github.com/amusi/awes ...

  3. GCN code parsing

    GCN code parsing 2018-07-18 20:39:11 utils.py  --- load data  def load_data(path="../data/cora/ ...

  4. Wijmo 2017 V1发布

    2017年Wijmo的第1个Release已经发布了!它充满了令人兴奋的新控件和新功能.一个新的TreeView控件:一个只有看到你才会相信的MultiAutoComplete控件:移动平台报表查看器 ...

  5. HDU 4311 Meeting point-1(曼哈顿距离最小)

    http://acm.hdu.edu.cn/showproblem.php?pid=4311 题意:在二维坐标中有n个点,现在要从这n个点中选出一个点,使得其他点到该点的曼哈顿距离总和最小. 思路: ...

  6. shp与json互转(转载)

    转自:http://blog.sina.com.cn/s/blog_673c98be0102v78i.html 对于搞GIS开发的,这2种数据格式太重要了. 一.shp转json 这个要容易些,方法也 ...

  7. 如何用R来定制个性化PPT

    ReporteRs包可以创建word,ppt,html文档.它可以格式化R的输出:如可编辑的矢量图,复杂的表格报告功能,企业模板文档的重用(.docx和.pptx).它是一个很好的自动化报告工具,并且 ...

  8. CSDN-markdown编辑器语法——字体、字号与颜色

     Markdown是一种可以使用普通文本编辑器编写的标记语言,通过类似HTML的标记语法,它可以使普通文本内容具有一定的格式.但是它本身是不支持修改字体.字号与颜色等功能的!   CSDN-markd ...

  9. React native中的组建通知通信:

    有这么一个需求,在B页面pop()回到A页面,需要A页面执行刷新,那么我们可以采用以下方法: 1:在A页面Push到B页面中,加上一个A页面中的刷新函数做为参数,然后在B页面中在pop()函数封装后通 ...

  10. 为 10000+ 业务系统提供数据可视化能力的 AntV 又进化了

    小蚂蚁说: 2018 年 AntV 品牌日以知新.知心为主题,旨在让产品一直「知新」,与用户一直「知心」.AntV 是蚂蚁金服全新一代数据可视化解决方案,致力于提供一套简单方便.专业可靠.无限可能的数 ...