Spring|Spring Dependency Injection

IoC的一个重点是在系统运行中,动态的向某个对象提供它所需要的其他对象。这一点是通过DI(Dependency Injection,依赖注入)来实现的。
配置文件中注入:

list1 list3 【Spring|Spring Dependency Injection】 map1 set1 p1

这种在配置文件中直接赋值的方法,对于某些固定的配置文件信息比较有用。比如存放配置文件的位置及名字
利用构造函数给bean的属性赋值
public class Person implements Serializable { private Long pid; //String private String pname; //引用类型 private Student student; //集合 private List list; private Set set; private Map map; //键值private Properties properties; //构造函数1 public Person(Long pid, Student student) { super(); this.pid = pid; this.student = student; } //构造函数2 public Person(String pname, Student student) { this.pname = pname; this.student = student; } //构造函数3 public Person() { } //构造函数4 public Person(Long pid, String pname, Student student, List list, Set set, Map map, Properties properties) { this.pid = pid; this.pname = pname; this.student = student; this.list = list; this.set = set; this.map = map; this.properties = properties; } //省略getter&setter方法 }

    推荐阅读