Spring容器
示例 代码
public class TestBean {
private String testStr = "1024";
public String getTestStr() {
return testStr;
}
public void setTestStr(String testStr) {
this.testStr = testStr;
}
}
class Test1 {
public static void main(String[] args) {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource("org/springframework/beans/demo/TestBeanEntity.xml"));
TestBean bean1 = (TestBean) bf.getBean("bean1");
System.out.println(bean1.getTestStr());
}
}
<?xml version="1.0" encoding="ISO-8859-1"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="bean1" class="org.springframework.tests.demo.TestBean"/>
</beans>
功能分析
- 读取配置文件
TestBeanEntity.xml- 根据文件中的配置,找到对应的类配置,并实例化
- 调用实例化的实例
博客围绕Spring容器展开,给出示例代码并进行功能分析,介绍其读取配置文件、实例化对应类配置及调用实例的过程,还提及了DefaultlistableBeanFactory。

被折叠的 条评论
为什么被折叠?



