Error creating bean with name 'injectionService' defined in URL [file:/D:/workspace2014/Spring/classes/spring-injection.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.imooc.ioc.injection.dao.InjectionDAO]: Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments?
检查spring-injection.xml里的注入方式只使用了其中一种,另外一种必须注释掉。例如,我只启用了设置注入方式:
<bean id="injectionService" class="com.imooc.ioc.injection.service.InjectionServiceImpl">
<property name="injectionDAO" ref="injectionDAO"></property>
</bean>
<!-- <bean id="injectionService" class="com.imooc.ioc.injection.service.InjectionServiceImpl"> -->
<!-- <constructor-arg name="injectionDAO_1" ref="injectionDAO"></constructor-arg> -->
<!-- </bean> -->
2. 还有几项要检查的,你直接看我下面代码中的注释吧
//使用设值注入时,配置文件中的property的name必须和属性名injectionDAO一致
private InjectionDAO injectionDAO;
//构造器注入,构造器参数名injectionDAO_1必须要和配置文件中的constructor-arg的name一致
// public InjectionServiceImpl(InjectionDAO injectionDAO_1) {
// this.injectionDAO = injectionDAO_1;
// }
//设值注入,使用该方法时,不能同时存在构造器注入方法,即上面的构造方法必须注释掉
public void setInjectionDAO(InjectionDAO injectionDAO) {
this.injectionDAO = injectionDAO;
}
injectionService未定义, TnjectionService的构造函数中缺少参数,参数类型为com.imooc.ioc.injection.dao.InjectionDAO