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替换成自己的包)

  • 相关阅读:
    OPENSSL库使用--AES篇
    Linux inotify功能及实现原理
    LSI RAID
    Linux下关于热插拔硬盘的指令
    最长回文字串理解(学习Manacher's algorithm)
    pat 1068 动态规划/Fina More Conis
    (二)Myeclipse中关于jdk配置,解决版本不一致问题
    (一)MyEclipse配置Tomcat,与jsp程序运行
    pat 1047 解题心得
    pat 1038 Smallest Number解题心得
  • 原文地址:https://www.cnblogs.com/phdeblog/p/12149091.html
Copyright © 2011-2022 走看看