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,如需轉載請自行聯系原作者