Spring3.0中弃用了dependency-check属性
在Bean被创建时Bean的属性(property)如果在配置文件Bean的定义中没有进行初始化赋值, 默认情况下Spring对于没有进行初始化的属性(property)是不做检查的。
* 但是很多情况下会要求Bean特定的属性必须进行初始化赋值,在Spring2.x中通过在bean标签中使用dependency-check属性设定由Spring进行强制检查的方式。
* denpendency-check属性有四个值 而既然Spring3中放弃使用了dependency-check属性一定就会有替代它的功能出现。
*
* 在spring3中替代dependency-check有4条建议:
*
* •Use constructors (constructor injection instead of setter injection) exclusively to ensure the right
* properties are set. •使用构造方法(使用构造方法注入替代setter注入)专门用来确认特定属性被初始化 •Create setters with a dedicated init method
* implemented. •用init方法初始化setter的属性 •Create setters with @Required annotation when the property is required.
* •在需要强制进行初始化的setters上标注
* @Required,可以参考http://www.mkyong.com/spring/spring-dependency-checking-with-required-annotation/ •Use
* @Autowired-driven injection which also implies a required property by default. •使用@Autowired-driven 注入也可以实现
*
资料来源:http://blog.csdn.net/arvinrong/article/details/7763180