我是 Spring 的新手,正在寻找细节学习。我正在阅读有关自动装配的内容并You cannot autowire so-called simple properties such as primitives, Strings, and Classes (and arrays of such simple properties) 在此处阅读。
1)我不明白Classes这里是什么意思?
2)他们说你不能自动装配素数,但我试过Integer包装类,他们仍然不工作,为什么?请参阅下面的代码。
豆子:
<bean id="teacher" class="com.climesoft.webapp.model.Teacher"
autowire="byName">
</bean>
<bean id="id" class="java.lang.Integer">
<constructor-arg value="20" />
</bean>
这里的Java类:
public class Teacher {
private String name;
// private int id;
private Integer id; // for autowiring
private String phone;
private Course course;
public Course getCourse() {
return course;
}
public void setCourse(Course course) {
this.course = course;
}
public Teacher() {
System.out.println("Calling Teacher No Param Constructor");
}
public Teacher(String name, Integer id, String phone) {
this.name = name;
this.id = id;
this.phone = phone;
System.out.println("Calling Teacher Param Constructor");
}
public String getName() {
System.out.println("Calling Teacher getName");
return name;
}
public void setName(String name) {
System.out.println("Calling Teacher setName");
this.name = name;
}
public Integer getId() {
System.out.println("Calling Teacher getId");
return id;
}
public void setId(Integer id) {
System.out.println("Calling Teacher setId");
this.id = id;
}
public String getPhone() {
System.out.println("Calling Teacher getPhone");
return phone;
}
public void setPhone(String phone) {
System.out.println("Calling Teacher setPhone");
this.phone = phone;
}
@Override
public String toString() {
return "Teacher [name=" + name + ", id=" + id + ", phone=" + phone + ", course=" + course + "]";
}
}
慕村9548890
子衿沉夜
忽然笑
相关分类