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

  • 相关阅读:
    python中的一些小知识
    软件工程第一次作业(2)
    CountDownLatch的理解和使用
    架构设计:系统间通信(1)概述从“聊天”开始上篇
    Asp默认的上传文件大小限制是200K
    当多个sqlserver服务存在时,需要完全限定的serverName 方可登陆
    关于Entity Framework 版本的疑惑
    mvc scaffolding
    sql 语句中的 NULL值
    如何从数据库生成 EF Code First model
  • 原文地址:https://www.cnblogs.com/hikoukay/p/11577961.html
Copyright © 2011-2022 走看看