注:默认模式是 none
package com.zyiz.netmon; public class Customer { private Person person; private int type; private String action; //getter and setter methods }
package com.zyiz.netmon; public class Person { private String name; private String address; private int age; //getter and setter methods }
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="CustomerBean" class="com.zyiz.netmon.Customer" > <property name="action" value="buy" /> </bean> <bean id="PersonBean" class="com.zyiz.netmon.Person"> <property name="name" value="zyiz" /> <property name="address" value="address ABC" /> <property name="age" value="29" /> </bean> </beans>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="CustomerBean" class="com.zyiz.netmon.Customer" dependency-check="simple"> <property name="person" ref="PersonBean" /> <property name="action" value="buy" /> </bean> <bean id="PersonBean" class="com.zyiz.netmon.Person"> <property name="name" value="zyiz" /> <property name="address" value="address ABC" /> <property name="age" value="29" /> </bean> </beans>
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.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="CustomerBean" class="com.zyiz.netmon.Customer" dependency-check="objects"> <property name="action" value="buy" /> <property name="type" value="1" /> </bean> <bean id="PersonBean" class="com.zyiz.netmon.Person"> <property name="name" value="zyiz" /> <property name="address" value="address ABC" /> <property name="age" value="29" /> </bean> </beans>
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.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="CustomerBean" class="com.zyiz.netmon.Customer" dependency-check="all"> <property name="action" value="buy" /> </bean> <bean id="PersonBean" class="com.zyiz.netmon.Person"> <property name="name" value="zyiz" /> <property name="address" value="address ABC" /> <property name="age" value="29" /> </bean> </beans>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" default-dependency-check="all"> <bean id="CustomerBean" class="com.zyiz.netmon.Customer"> <property name="action" value="buy" /> <property name="type" value="1" /> </bean> <bean id="PersonBean" class="com.zyiz.netmon.Person"> <property name="name" value="zyiz" /> <property name="address" value="address ABC" /> <property name="age" value="29" /> </bean> </beans>