[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)
| 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类的更多相关文章
- Spring 创建 IOC 容器 ClassPathXmlApplicationContext 类
一.ClassPathXmlApplicationContext 类的作用 在 Java 环境中使用 Spring 时,需要用 new ClassPathXmlApplicationContext(c ...
- 使用spring配置类代替xml配置文件注册bean类
spring配置类,即在类上加@Configuration注解,使用这种配置类来注册bean,效果与xml文件是完全一样的,只是创建springIOC容器的方式不同: //通过xml文件创建sprin ...
- Spring自定义类扫描器 ClassPathScanningCandidateComponentProvider
项目中有个需求 读取xml文件,然后 对xml文件进行解析,比如如果是 Gender=0/1的话,分别代表男女. 所以需要在构造函数之后,初始化bean之前进行过滤解析 xml文件: <inte ...
- Spring普通类/工具类获取并调用Spring service对象的方法
参考<Spring普通类获取并调用Spring service方法>,网址:https://blog.csdn.net/jiayi_0803/article/details/6892455 ...
- spring 工具类大集合
接以前的文章 apache-commons 常用工具类 和文章 apache-commons 工具类扩展 小家 Spring 对 spring 的工具类做了详细的介绍(一) 这里我抽出一些好用的类,不 ...
- 521我发誓读完本文,再也不会担心Spring配置类问题了
当大潮退去,才知道谁在裸泳.关注公众号[BAT的乌托邦]开启专栏式学习,拒绝浅尝辄止.本文 https://www.yourbatman.cn 已收录,里面一并有Spring技术栈.MyBatis.中 ...
- Spring配置类深度剖析-总结篇(手绘流程图,可白嫖)
生命太短暂,不要去做一些根本没有人想要的东西.本文已被 https://www.yourbatman.cn 收录,里面一并有Spring技术栈.MyBatis.JVM.中间件等小而美的专栏供以免费学习 ...
- Spring同一个类中的注解方法调用AOP失效问题总结
public interface XxxService { // a -> b void a(); void b(); } @Slf4j public class XxxServiceImpl ...
- Spring工具类 非spring管理环境中获取bean及环境配置
SpringUtils.java import org.springframework.beans.BeansException; import org.springframework.beans.f ...
随机推荐
- Android之单元测试及数据库操作
一.安卓下的单元测试1.创建一个单元类,继承超类AndroidTestCase2.在AndroidManifest.xml配置清单中配置以下两点首先在manifest节点下添加节点instrument ...
- Linux下查看网卡驱动和版本信息
Linux下查看网卡驱动和版本信息 查看网卡生产厂商和信号 查看基本信息:lspci 查看详细信息:lspci -vvv # 3个小写的v 查看网卡信息:lspci | grep Ethernet 查 ...
- HihoCoder 1236 Scores - bitset - 分块
Kyle is a student of Programming Monkey Elementary School. Just as others, he is deeply concerned wi ...
- 配置maven默认jdk版本
1.在setting.xml中配置.对所有通过该配置文件构建的maven项目有效. <profile> <id>jdk-1.8</id> <activatio ...
- Golang踩坑录 两种方式来读取文件一行所导致的问题
前两天零零碎碎看完了golang的基础,想着找个小项目练练手,可是出现了一个十分棘手的问题 我要做的东西是网站路径爆破 所以我会从文本字典中把一行行路径读取然后与域名拼接,但是我在跑起程序后出现了问题 ...
- Java日期时间(Date/Time)
获取当前日期和时间 在Java中容易得到当前的日期和时间.可以使用一个简单的Date对象的toString()方法,如下所示打印当前日期和时间: import java.util.Date; publ ...
- (转)Applications of Reinforcement Learning in Real World
Applications of Reinforcement Learning in Real World 2018-08-05 18:58:04 This blog is copied from: h ...
- [JavaScript] - js
原题 var countSheep = function (num){ //your code here var str = ' sheep...'; var result = ''; for (va ...
- 【译】第10节---数据注解-Key
原文:http://www.entityframeworktutorial.net/code-first/key-dataannotations-attribute-in-code-first.asp ...
- C# 委托例子
两个子窗口向一个主窗口发送信息 主窗口: using System; using System.Collections.Generic; using System.ComponentModel; us ...