使用autowire标签完成bean的自动注入
首先,我们有如下两个类:
public class Student{
private String name;
private Book book;
//set and get methods
}
class Book{
private int ID;
//set and get methods
}
autowire=“byName”,根据成员变量名字进行注入
<?xml version="1.0" encoding="UTF-8"?>
<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">