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

  • 相关阅读:
    寒假学习笔记(15)
    寒假学习笔记(14)
    CSS(二) 文字样式属性,背景和列表
    CSS(一)基础
    Django初始化项目时报错
    数据表生成以及apps目录建立
    Django导入静态文件
    IntelliJ Idea 常用快捷键列表
    水木告白工作室:Thymeleaf模板引擎
    水木告白工作室:CSS3之路 (一:圆角、边框、背景)
  • 原文地址:https://www.cnblogs.com/phdeblog/p/12149091.html
Copyright © 2011-2022 走看看