博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring的属性依赖检查
阅读量:4952 次
发布时间:2019-06-12

本文共 2126 字,大约阅读时间需要 7 分钟。

Spring支持4种依赖检查:默认的是none

    • none – No dependency checking.
    • simple – If any properties of primitive type (int, long,double…) and collection types (map, list..) have not been set, UnsatisfiedDependencyException will be thrown.
    • objects – If any properties of object type have not been set, UnsatisfiedDependencyException will be thrown.

     all – If any properties of any type have not been set, an UnsatisfiedDependencyException will be thrown.

举个例子:

public class Customer {	private Person person;	private int type;	private String action; 	//getter and setter methods}

  

public class Person {	private String name;	private String address;	private int age; 	//getter and setter methods	}

  

1. none dependency checking

  

2. simple dependency checking

  注意此处type字段故意没有设置,这样会出现UnsatisfiedDependencyException

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'CustomerBean' defined in class path resource [config/Spring-Customer.xml]: Unsatisfied dependency expressed through bean property 'type': Set this property value or disable dependency checking for this bean.

3. objects dependency checking

  此处故意没有设置”person“属性,会出现UnsatisfiedDependencyException

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'CustomerBean' defined in class path resource [config/Spring-Customer.xml]: Unsatisfied dependency expressed through bean property 'person': Set this property value or disable dependency checking for this bean.

4. all dependency checking

  

Global default dependency checking:

default-dependency-check="all"

  

转载于:https://www.cnblogs.com/rollenholt/archive/2012/12/27/2835270.html

你可能感兴趣的文章
算法18-----判断是否存在符合条件的元素【list】
查看>>
《刑法》关于拐卖妇女儿童犯罪的规定
查看>>
Windows的本地时间(LocalTime)、系统时间(SystemTime)、格林威治时间(UTC-Time)、文件时间(FileTime)之间的转换...
查看>>
alias重启后失效了
查看>>
RestTemplate的Object与Entity的区别
查看>>
Fireworks基本使用
查看>>
《代码整洁之道》学习记录
查看>>
C++深入理解虚函数
查看>>
c#线程学习笔记一---基本概念
查看>>
2018-4-13
查看>>
两台电脑间的消息传输
查看>>
Linux 标准 I/O 库
查看>>
Spring Data JPA教程, 第八部分:Adding Functionality to a Repository (未翻译)
查看>>
教练技术的小应用
查看>>
.net Tuple特性
查看>>
Java基础常见英语词汇
查看>>
iOS并发编程笔记【转】
查看>>
泛型 T的定义<1>
查看>>
thinkphp dispaly和fetch的区别
查看>>
08号团队-团队任务5:项目总结会
查看>>