1.構(gòu)造器注入
/**
* 構(gòu)造器注入
* @param injectionDAO
*/
public injectionServiceimpl(injectionDAO injectionDAO) {
this.injectionDAO = injectionDAO;
}
xml bean配置
name應(yīng)該與構(gòu)造函數(shù)的參數(shù)名字一致
<bean id="injectionService" class="com.spring.ioc.injection.service.injectionServiceimpl">
<constructor-arg name="injectionDAO" ref="injectionDAO"></constructor-arg>
</bean>
2.設(shè)置注入
需要對(duì)變量設(shè)置set方法品擎,通過set方法賦值來(lái)注入
/**
* 設(shè)值注入
*/
public void setInjectionDAO(com.spring.ioc.injection.Dao.injectionDAO injectionDAO) {
this.injectionDAO = injectionDAO;
}
xml bean配置
name應(yīng)該與構(gòu)造函數(shù)的參數(shù)名字一致
<bean id="injectionService" class="com.spring.ioc.injection.service.injectionServiceimpl">
<property name="injectionDAO" ref="injectionDAO"></property>
</bean>