一、demo示例
1、实体类
package cn.jin.test;
public class MyTestBean {
private String str = "this is test";
public String getStr() {
return str;
}
public void setStr(String str) {
this.str = str;
}
}
2、配置beanFactoryTest.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="testBean" class="cn.jin.test.MyTestBean"></bean>
</beans>
3、读取
@SuppressWarnings("deprecation")
public static void main(String[] args) {
XmlBeanFactory xmlBean = new XmlBeanFactory(new ClassPathResource("beanFactoryTest.xml"));
MyTestBean bean = (MyTestBean)xmlBean.getBean("testBean");
System.out.println(bean.getStr());
//SpringApplication.run(Application.class, args);
}
二、读取配置文件解析
1、封装资源文件
在读取到这个类XmlBeanDefinitionReader对参数编码,如果设置编码,spring会使用相应的编码作为输出流的编码