zoukankan      html  css  js  c++  java
  • springboot available: expected at least 1 bean which qualifies as autowire candidate奇葩问题

    Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'apiUserController': Unsatisfied dependency expressed through field 'apiMutiHttpClientUtil'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.crt.openapi.utils.ApiMutiHttpClientUtil' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

     Description:

    Field apiMutiHttpClientUtil in com.crt.openapi.apiinterface.controller.base.CommonController required a bean of type 'com.crt.openapi.utils.ApiMutiHttpClientUtil' that could not be found.

    The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)

    Action:

    Consider defining a bean of type 'com.crt.openapi.utils.ApiMutiHttpClientUtil' in your configuration.

     总是提示无法注入Service或者Dao中的Bean!

    后来经研究发现,SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描!

     “Application类”是指SpringBoot项目入口类。这个类的位置很关键:

     如果Application类所在的包为:com.demo.module,则只会扫描com.demo.module包及其所有子包,如果service或dao所在包不在com.demo.module及其子包下,则不会被扫描!

     所以需在application启动类中加上

     @MapperScan("com.*.dao")//加上你项目的dao或service所在文件位置即可

    @SpringBootApplication

  • 相关阅读:
    【JavaScript】照片库
    【JavaScript】事件介绍
    【JavaScript】函数返回值
    【JavaScript】打造自己的函数
    【JavaScript】函数—可重用的代码块
    【JavaScript】循环语句
    【JavaScript】笑话生成器
    【JavaScript】数组
    c#之线程通信
    c#之线程同步
  • 原文地址:https://www.cnblogs.com/hikoukay/p/11577961.html
Copyright © 2011-2022 走看看