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

  • 相关阅读:
    Collectors.reducing总结
    Ubuntu 换源看这一篇就够了
    基于Vue2和Node.js的反欺诈系统设计与实现
    Flink源码解析(四)——从Flink集群部署和任务提交模式看Flink任务的核心组件
    SaaS架构(二) 多租户数据隔离方案
    网络IO模型(BIO,NIO,AIO)
    Gale-Shapley算法
    Java 内存模型
    上位机那些事儿
    三菱PLC之SLMP协议报文说明
  • 原文地址:https://www.cnblogs.com/luffyxin/p/9714390.html
Copyright © 2011-2022 走看看