Spring配置
-
alias
<alias name="user" alias="userNes"/>
如果添加了别名,我们也可以使用别名获取对象
-
bean
<bean id="user" class="com.User" name="user2,u2" >
<property name="name" value="YanAemons"/>
</bean>id: bean的唯一标识符,也就是相当于我们学过的对象名
class:bean对象所对应的全限定名:包名 + 类型
name:别名(可以同时取多个别名),类似alias
-
import
依赖注入
-
构造器注入
上文已经说过
-
Set方式注入【重点】
-
依赖注入:Set注入
-
依赖:bean对象的创建依赖于容器
-
注入:bean对象中的所有属性,由容器来注入
// Student Class
import java.util.*;
public class Student {
private String name;
private Address address;
private String[] books;
private List<String> hobbies;
private Map<String, String> card;
private Set<String> games;
private String wife;
private Properties info;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public String[] getBooks() {
return books;
}
public void setBooks(String[] books) {
this.books = books;
}
public List<String> getHobbys() {
return hobbies;
}
public void setHobbys(List<String> hobbies) {
this.hobbies = hobbies;
}
public Map<String, String> getCard() {
return card;
}
public void setCard(Map<String, String> card) {
this.card = card;
}
public Set<String> getGames() {
return games;
}
public void setGames(Set<String> games) {
this.games = games;
}
public String getWife() {
return wife;
}
public void setWife(String wife) {
this.
-
-