美文网首页
Spring 依赖检查

Spring 依赖检查

作者: ChanHsu | 来源:发表于2017-04-28 16:28 被阅读72次

在Spring中,可以使用依赖检查功能,以确保所要求的属性可设置或者注入

依赖检查模式

4个依赖检查支持的模式:

  • none – 没有依赖检查,这是默认的模式。
  • simple – 如果基本类型(int, long,double…)和集合类型(map, list..)的任何属性都没有设置,UnsatisfiedDependencyException将被抛出。
dependency-check="simple"
  • objects – 如果对象类型的任何属性都没有设置,UnsatisfiedDependencyException将被抛出。
dependency-check="objects "
  • all – 如果任何类型的任何属性都没有被设置,UnsatisfiedDependencyException将被抛出。
dependency-check="all"

注:默认模式是 none

全局默认的依赖检查

default-dependency-check="all"

@Required

在 setPerson()方法,以确保 person 属性已设置。
1.包函 <context:annotation-config />
2.包函 RequiredAnnotationBeanPostProcessor

@Required-style 注解

相关文章

网友评论

      本文标题:Spring 依赖检查

      本文链接:https://www.haomeiwen.com/subject/jfcazttx.html