注:默认模式是 none
package com.h3.common;
public class customer
{
private person person;
private int type;
private string action;
//getter and setter methods
}
package com.h3.common;
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.h3.common.customer" > <property name="action" value="buy" /> </bean> <bean id="personbean" class="com.h3.common.person"> <property name="name" value="h3" /> <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.h3.common.customer"
dependency-check="simple">
<property name="person" ref="personbean" />
<property name="action" value="buy" />
</bean>
<bean id="personbean" class="com.h3.common.person">
<property name="name" value="h3" />
<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.h3.common.customer"
dependency-check="objects">
<property name="action" value="buy" />
<property name="type" value="1" />
</bean>
<bean id="personbean" class="com.h3.common.person">
<property name="name" value="h3" />
<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.h3.common.customer"
dependency-check="all">
<property name="action" value="buy" />
</bean>
<bean id="personbean" class="com.h3.common.person">
<property name="name" value="h3" />
<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.h3.common.customer"> <property name="action" value="buy" /> <property name="type" value="1" /> </bean> <bean id="personbean" class="com.h3.common.person"> <property name="name" value="h3" /> <property name="address" value="address abc" /> <property name="age" value="29" /> </bean> </beans>