UnsatisfiedDependencyException NoUniqueBeanDefinitionException

06-Jan-2018 15:39:27.905 SEVERE [http-nio-8080-exec-3] org.apache.catalina.core.ApplicationContext.log StandardWrapper.Throwable

 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'categoryController': Unsatisfied dependency expressed through field 'categoryService'; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.ssm.blog.service.CategoryService' available: expected single matching bean but found 2: AAService,categoryServiceImpl

注入失败原因是NoUniqueBeanDefinitionException定义的bean不唯一

[java]  view plain  copy
  1. @Controller  
  2. @RequestMapping("/category.html")  
  3. public class CategoryController {  
  4.   
  5.     @Autowired  
  6.     private CategoryService categoryService;  

controller中通过@Autowared注入的CategoryService,而现在我的CategoryService有两个实现类,AAService和CategoryServiceImpl。@Autowared默认按类型注入,现在这个类型有多个实现类,所以就不知道注入哪个了。

解决办法是:如果是AAService写错了,它不该实现CategoryService接口,那就改一下AAService。如果一个接口需要有多个实现类,就换成@Resource按名称注入指明调用哪个实现类

[java]  view plain  copy
  1. @Controller  
  2. @RequestMapping("/category.html")  
  3. public class CategoryController {  
  4.   
  5.     @Resource(name="categoryServiceImpl")  
  6.     private CategoryService categoryService;  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值