<!-- customer has a property name "address" --> <bean id="customer" class="com.tw511.common.Customer" autowire="byName" /> <bean id="address" class="com.tw511.common.Address" > <property name="fulladdress" value="YiLong Road, CA 188" /> </bean>
這裡有兩個 beans, 分別是:customer 和 address.
package com.tw511.common; public class Customer { private Address address; //... }
package com.tw511.common; public class Address { private String fulladdress; //... }
<bean id="customer" class="com.tw511.common.Customer" > <property name="address" ref="address" /> </bean> <bean id="address" class="com.tw511.common.Address" > <property name="fulladdress" value="YiLong Road, CA 188" /> </bean>
輸出
Customer [address=Address [fulladdress=YiLong Road, CA 188]]
<bean id="customer" class="com.tw511.common.Customer" autowire="byName" /> <bean id="address" class="com.tw511.common.Address" > <property name="fulladdress" value="YiLong Road, CA 188" /> </bean>
輸出
Customer [address=Address [fulladdress=YiLong Road, CA 188]]
<bean id="customer" class="com.tw511.common.Customer" autowire="byName" /> <bean id="addressABC" class="com.tw511.common.Address" > <property name="fulladdress" value="Block A 888, CA" /> </bean>
輸出
Customer [address=null]