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.
举个例子:
1
2
3
4
5
6
7
8
<code>public class Customer</code>
<code>{</code>
<code> </code><code>private Person person;</code>
<code> </code><code>private int type;</code>
<code> </code><code>private String action;</code>
<code> </code>
<code> </code><code>//getter and setter methods</code>
<code>}</code>
<code>public class Person</code>
<code> </code><code>private String name;</code>
<code> </code><code>private String address;</code>
<code> </code><code>private int age;</code>
9
10
11
12
13
14
15
16
<code><</code><code>beans</code> <code>xmlns="http://www.springframework.org/schema/beans"</code>
<code> </code><code>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"</code>
<code> </code><code>xsi:schemaLocation="http://www.springframework.org/schema/beans</code>
<code> </code><code>http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"></code>
<code> </code><code><</code><code>bean</code> <code>id="CustomerBean" class="com.mkyong.common.Customer" ></code>
<code> </code><code><</code><code>property</code> <code>name="action" value="buy" /></code>
<code> </code><code></</code><code>bean</code><code>></code>
<code> </code><code><</code><code>bean</code> <code>id="PersonBean" class="com.mkyong.common.Person"></code>
<code> </code><code><</code><code>property</code> <code>name="name" value="mkyong" /></code>
<code> </code><code><</code><code>property</code> <code>name="address" value="address ABC" /></code>
<code> </code><code><</code><code>property</code> <code>name="age" value="29" /></code>
<code></</code><code>beans</code><code>></code>
17
18
19
<code> </code><code><</code><code>bean</code> <code>id="CustomerBean" class="com.mkyong.common.Customer"</code>
<code> </code><code>dependency-check="simple"></code>
<code> </code><code><</code><code>property</code> <code>name="person" ref="PersonBean" /></code>
注意此处type字段故意没有设置,这样会出现UnsatisfiedDependencyException
<code> </code><code>dependency-check="objects"></code>
<code> </code><code><</code><code>property</code> <code>name="type" value="1" /></code>
此处故意没有设置”person“属性,会出现UnsatisfiedDependencyException
<code> </code><code>dependency-check="all"></code>
<code> </code><code>http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"</code>
<code> </code><code>default-dependency-check="all"></code>
<code> </code><code><</code><code>bean</code> <code>id="CustomerBean" class="com.mkyong.common.Customer"></code>
==============================================================================
本文转自被遗忘的博客园博客,原文链接:http://www.cnblogs.com/rollenholt/archive/2012/12/27/2835270.html,如需转载请自行联系原作者