package com.yiibai.common;
public class Developer {
private Language language;
//autowire by constructor
public Developer(Language language) {
this.language = language;
}
//...
}
package com.yiibai.common;
public class Language {
private String name;
//...
}
Spring装配
第一种
<bean id="developer" class="com.yiibai.common.Developer">
<constructor-arg>
<ref bean="language" />
</constructor-arg>
</bean>
<bean id="language" class="com.yiibai.common.Language" >
<property name="name" value="Java" />
</bean>
第二种
<bean id="developer" class="com.yiibai.common.Developer" autowire="constructor" />
<bean id="language" class="com.yiibai.common.Language" >
<property name="name" value="Java" />
</bean>