springmvc注入类 NoUniqueBeanDefinitionException: No qualifying bean of type [] is defined: expected single错误
在springmvc中注入服务时用@Service
当有两个实现类时都标明@Service后则会出现异常:
nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.james.dao.impl.BaseDao] is defined: expected single matching bean but found 2:
这是因为都标明了@Service会自动注入,这时会导致不清楚实际运行时实例化哪一类。
解决:
方法一
实际运用哪一个实现类就在哪个类上注入@Service,另外一个不标注
方法二
都不标注@Service,在resource文件夹中配置 applicationContext.xml,表明实际运行哪个实现类。
<bean id="serviceImpl" class="com.james.service.impl.ServiceImpl"></bean>
作者:欢醉
公众号【一个码农的日常】 技术群:319931204 1号群: 437802986 2号群: 340250479
出处:http://zhangs1986.cnblogs.com/
码云:https://gitee.com/huanzui
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
公众号【一个码农的日常】 技术群:319931204 1号群: 437802986 2号群: 340250479
出处:http://zhangs1986.cnblogs.com/
码云:https://gitee.com/huanzui
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。