<!-- customer has a property name "address" --> <bean id="customer" class="com.zyiz.netmon.Customer" autowire="byName" /> <bean id="address" class="com.zyiz.netmon.Address" > <property name="fulladdress" value="YiLong Road, CA 188" /> </bean>
这里有两个 beans, 分别是:customer 和 address.
package com.zyiz.netmon; public class Customer { private Address address; //... }
package com.zyiz.netmon; public class Address { private String fulladdress; //... }
<bean id="customer" class="com.zyiz.netmon.Customer" > <property name="address" ref="address" /> </bean> <bean id="address" class="com.zyiz.netmon.Address" > <property name="fulladdress" value="YiLong Road, CA 188" /> </bean>
输出
Customer [address=Address [fulladdress=YiLong Road, CA 188]]
<bean id="customer" class="com.zyiz.netmon.Customer" autowire="byName" /> <bean id="address" class="com.zyiz.netmon.Address" > <property name="fulladdress" value="YiLong Road, CA 188" /> </bean>
输出
Customer [address=Address [fulladdress=YiLong Road, CA 188]]
<bean id="customer" class="com.zyiz.netmon.Customer" autowire="byName" /> <bean id="addressABC" class="com.zyiz.netmon.Address" > <property name="fulladdress" value="Block A 888, CA" /> </bean>
输出
Customer [address=null]