zoukankan      html  css  js  c++  java
  • org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [dx.service.ItemService] found for dependency

    在整合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:初学者记录

  • 相关阅读:
    设计模式C++描述----15.策略(Strategy)模式
    设计模式C++描述----14.外观(Facade)模式
    设计模式C++描述----12.享元(Flyweight)模式
    设计模式C++描述----13.代理(Proxy)模式
    设计模式C++描述----11.组合(Composite)模式
    设计模式C++描述----10.装饰(Decorator)模式
    爬虫之urllib包以及request模块和parse模块
    爬虫简介
    爬虫知识总汇
    Django之admin的使用和源码剖析
  • 原文地址:https://www.cnblogs.com/luffyxin/p/9714390.html
Copyright © 2011-2022 走看看