本篇文章的目的 是 了解 spring ioc 启动 ,创建bean 到获取bean的时候,ioc 都做了些什么
文章很长,并且我能力有限,慎看,
之前 看过知乎上有 大佬说过, 带着目的看源码才是学习的正确方法,不要为了 看源码而看源码,
这样的学习是无效的
测试工具 idea
测试准备:
测试类 (javabean) : Person
Person 实现
public class Person {
private String name;
private Integer age;
public Person(){}
public Person(String name,int age){
this.name = name;
this.age = age;
}
/**
* setter and getter
*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
@Override
public String toString() {
return this.name + " " + this.age;
}
}
配置 spring xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!--suppress ALL -->
<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 http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--第一个bean-->
<bean id="person1" class="com.yg.springSource.Person">
<property name="name" value="杨小光"></property>
<property name="age" value="19"></property>