注释分类:
- @Required
- @Autowired
- @Qualifer
一. @Required
public class Student {
private Integer age;
private String name;
@Required
public void setAge(Integer age) {
this.age = age;
}
public Integer getAge() {
return age;
}
@Required
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
<!-- Definition for student bean -->
<bean id="student" class="com.zhw.test.Student">
<property name="name" value="Zara" />
<property name="age" value="25" />
<!-- try without passing age and check the result :result表明:在student中使用过@required注释过的属性必须包含在bean的property属性中-->
result表明:在student中使用过@required注释过的属性必须包含在bean的property属性中,否则报错