(转载)spring 3.0中添加bean 的dependency-check属性 报错。

 

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

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值