这是我到目前为止所做的。
我的学生班:
public class Student {
public String name;
public String getName() {
return name;
}
@Required
public void setName(String name) {
this.name = name;
}
}
BeanDefination类:
@Configuration
public class BeanDefination
{
@Bean
public Student student() {
Student s = new Student();
// s.setName("Shiva");
return s;
}
}
使用TestDemo类的客户端:
public class TestDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
AnnotationConfigApplicationContext factory = new AnnotationConfigApplicationContext();
factory.register(BeanDefination.class);
factory.refresh();
Student student = (Student) factory.getBean(Student.class);
System.out.println(student.getName());
}
}
那么如果未设置所需的值,我没有收到错误,这是错误的吗?