1.构造器注入
/**
* 构造器注入
* @param injectionDAO
*/
public injectionServiceimpl(injectionDAO injectionDAO) {
this.injectionDAO = injectionDAO;
}
xml bean配置
name应该与构造函数的参数名字一致
<bean id="injectionService" class="com.spring.ioc.injection.service.injectionServiceimpl">
<constructor-arg name="injectionDAO" ref="injectionDAO"></constructor-arg>
</bean>
2.设置注入
需要对变量设置set方法,通过set方法赋值来注入
/**
* 设值注入
*/
public void setInjectionDAO(com.spring.ioc.injection.Dao.injectionDAO injectionDAO) {
this.injectionDAO = injectionDAO;
}
xml bean配置
name应该与构造函数的参数名字一致
<bean id="injectionService" class="com.spring.ioc.injection.service.injectionServiceimpl">
<property name="injectionDAO" ref="injectionDAO"></property>
</bean>
网友评论