码迷,mamicode.com
首页 > 编程语言 > 详细

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [dx.service.ItemService] found for dependency

时间:2018-09-27 18:01:13      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:spl   factor   ati   least   creation   ESS   div   hide   not   

在整合ssm框架,测试service层的时候报错

技术分享图片
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [dx.service.ItemService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1308)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:530)
    ... 27 more

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘Test.ItemServiceTest‘: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private dx.service.ItemService Test.ItemServiceTest.itemService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [dx.service.ItemService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
View Code

这里是service依赖注入失败,后来发现在applicationContext.xml要配置

  <context:annotation-config />
    <context:component-scan base-package="dx.service" />

springmvc.xml里面也要配置

      
        <!-- 扫描@Controler  @Service   -->
        <context:component-scan base-package="dx"/>

然后问题就解决了。

ps:初学者记录

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [dx.service.ItemService] found for dependency

标签:spl   factor   ati   least   creation   ESS   div   hide   not   

原文地址:https://www.cnblogs.com/luffyxin/p/9714390.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!