三个接口:
BeanFactory :Ioc容器,面向spring本身 (父) 1.手工加载postProcess. 2.getBean()的时候初始bean
ApplicationContext:Spring容器,面向开发者 (子) 1.postProcess配置文件中定义就可以了. 2.加载配置文件的时候就init bean (scope="prototype")
WebApplicationContext:面向Web,同时 bean可以是request,session,application,singleton,prototype
ApplicationContext的实现类
加载spring配置文件:ClassPathXmlApplicationContext , FileSystemXmlApplicationContext
1.构造Resource,用来加载配置文件(可以加载所有文件)
加载资源:(任意资源) ,这是因为ApplicationContext是ResourceLoader的子接口,该在接口定义方法getResource()
Resource res1 = ApplicationContext
.getResource("file:/D:/masterSpring/chapter3/src/com/baobaotao/context/resource.txt");
Resource res = new ClassPathResource("com/baobaotao/beanfactory/beans.xml")
//res1.getInputStream(); 可以把Resource转换成为InputStream,或者其他你希望的流 (Resource 还有其他的子接口和实现类?)
2.XmlBeanFactory reads bean definitions from an XML document ,这是一个很重要的类 !!!
BeanFactory bf = new XmlBeanFactory(res);//resource做为参数
Car car = (Car) bf.getBean("car");
2.如果resource是一个普通的文件,可以按一般文件来读内容
FileReader fr = new FileReader(res1.getFile());
BufferedReader br = new BufferedReader(fr);
String strText= "";
while ( (strText = br.readLine())!=null){
System.out.println(strText);
}
3.对于加载配置文件,也可以通过这样的方式,简单快速
String[] CONFIG_FILES = {"com/baobaotao/context/beans.xml"};
ApplicationContext ctx = new ClassPathXmlApplicationContext(CONFIG_FILES);
ApplicationContext ctx = new FileSystemXmlApplicationContext(CONFIG_FILES);
ctx.getBean("car");
org.springframework.util,Assert
org.springframework.util.ResourceUtils
Resource res1 = ctx
.getResource(ResourceUtils.CLASSPATH_URL_PREFIX+"com/baobaotao/context/resource.txt");
分享到:
相关推荐
org.springframework.beans-3.0.5工程所需jar包,com.springsource.net.sf.cglib-2.2.0.jar、 ...javax.inject.jar、 javax.servlet.jsp.jar、 org.springframework.core-3.0.5.RELEASE.jar
Attachment B Models for Dividing Fractions 附件 B 分数除法模型.doc
Attachment 1_chazhi.xlsx
Packtpub.Drupal.6.Attachment.Views.Feb.2010.rar
UL 498-2021-Attachment Plugs and Receptacles.rar
UL 498-2021-Attachment Plugs and Receptacles.pdf
UL 498-2023-附件插头和插座Attachment Plugs and Receptacles.rar
精品教育教学资料
能够掌握默认网站的基本配置以及原理;能够掌握虚拟目录的基本配置;能够熟练的掌握虚拟主机的配置;能够增强网站安全性的基本方法;实验拓扑: HYPERLINK...
40. Auto-Launch a file attachment 87 41. Showing a response count without showing the responses 89 42. 常用的几个按钮收集 91 43. 在WEB上从视图删除文档技巧 93 44. 在Domino Designer中使用XML数据 96 45. ...
Attachment 84 Abstract Belt conveyor is a kind of friction driven to transport materials in a continuous way machinery. It Is mainly composed of irame conveyor belt, supporting roller, roller, ...
" " "扫描状态用) " "delivery_useful_address_info用户地址 " " "信息 " " "factorage_journal " 第三方支付的手续费记录表 " "第三方支付的手续费记录表 " " "field_certification_attachment认证附 " " "件 " " ...
~\attachment")+ "1.png"; System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.OpenOrCreate,System.IO.FileAccess.Write); printPicture.Save(fs, System.Drawing....
4. 请看附件(Pls see attachment):这是一个常用的回复语句,意思是请查看附件中的文件或信息。 5. 签回电放信(Pls sign back the telex release letter):这是一个要求对方签回电放信的回复,确认货物的所有权...
直流电动机的MATLAB仿真设计 本文主要介绍了使用MATLAB对直流电动机的仿真设计,包括直流电动机的直接起动、串联电阻启动、能耗制动和反接制动四种仿真模型的建立和仿真...attachment 4:直流电动机反接制动仿真结果
JS中自定义类和对象,工厂方法,构造函数,混合使用工厂方法和Prototype,修改对象
SATA(Serial Advanced Technology Attachment)是一种串行硬盘接口,用于连接硬盘和主机板。USB(Universal Serial Bus)是一种通用串行总线接口,用于连接外设和主机板。 CPCI接口定义标准是工业自动化和医疗设备...
* 背景滚动:background-attachment 属性用于设置背景图片的滚动方式,取值可以是 scroll、fixed 等。 区块属性: * 字间距:letter-spacing 属性用于设置文本的字间距,取值可以是 normal 或数值。 * 对齐:text-...