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

  • 相关阅读:
    hdu 1088 HTML解析
    hdu1171 转化01背包,组合
    Java编程优化之旅(一)一般化方法
    Java简单实现Socket非阻塞通信
    Maven安装,以及导入Intellij IDEA
    笔记本的使用技巧
    Intellij IDEA使用小技巧
    学习Spring有关知识
    学习安装IntelliJ IDEA
    C#后台调用js方法无效果,未解决。
  • 原文地址:https://www.cnblogs.com/phdeblog/p/12149091.html
Copyright © 2011-2022 走看看