zoukankan      html  css  js  c++  java
  • SSM Service自动注入失败

    报错先贴出来:

    Error creating bean with name 'testController': 
    Unsatisfied dependency expressed through field 'userInfoService': No qualifying bean of type [bcs.wms.service.UserInfoService] found for dependency [bcs.wms.service.UserInfoService]:
    expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)};
    nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [bcs.wms.service.UserInfoService] found for dependency [bcs.wms.service.UserInfoService]:
    expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

    在控制器自动注入Service时报以上错误。

    1、首先要确保语法正确(包括已添加@Service注解)

    2、其次要看配置文件有没有配置相关的自动扫描,并且很可能不止要在一个文件里要配置。

    spring的配置文件要配置,spring-mvc的配置文件也要配置。本次出错正是因为没有在spring-mvc的配置文件里配置,才导致controller层自动注入Service时出错。

    解决方案:

    在spring、springmvc的配置文件中,都要加上:

       <context:component-scan base-package="bcs.wms.service"/>        (bcs.wms.service替换成自己的包)

  • 相关阅读:
    python+OpenCV 特征点检测
    如何使用《DB 查询分析器》高效地生成旬报货运量数据
    Hive-RCFile文件存储格式
    NET:交换机的背板带宽,交换容量,包转发率区别
    css:cdata
    [ZOJ 3623] Battle Ships
    [NYOJ 860] 又见01背包
    [Uva 11825] Hackers’ Crackdown
    2014-10-29
    [转] 三鲜之所在
  • 原文地址:https://www.cnblogs.com/phdeblog/p/12149091.html
Copyright © 2011-2022 走看看