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
springboot available: expected at least 1 bean which qualifies as autowire candidate奇葩问题的更多相关文章
- Caused by:org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type "" available: expected at least 1 bean which qualifies as autowire candidate
项目使用spring, mybatis.因为分了多个模块,所以会这个模块引用了其它模块的现在,结果使用Junit测试的时候发现有两个模块不能自动注入dao和service问题.解决后在此记录一下. 解 ...
- spring加载bean报错:expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
看具体报错日志: 警告: Unable to proxy interface-implementing method [public final void cn.wlf.selection.proto ...
- NoSuchBeanDefinitionException:No qualifying bean of type found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
报错如下: NoSuchBeanDefinitionException:No qualifying bean of type found for dependency: expected at l ...
- No matching bean of type [xx] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency
这个看起来很弱爆的问题其实是因为其他的配置文件中已经出现了为xx定义好的注入.如果用@Autowired就会得到上面的错误 , 但是用@Resource的时候就会看到类似下面的错误 Bean name ...
- mybatis expected at least 1 bean which qualifies as autowire candidate for this dependency
错误原因:没有引入相应mapper接口,导致spring没有找到依赖 解决方法一:使用注解的方法: 首先在spring配置文件中添加 <bean class="org.mybatis. ...
- NoSuchBeanDefinitionException: No qualifying bean of type 'com.bj186.ssm.mapper.EmployeeMapper' available: expected at least 1 bean which qualifies as autowire candidate
在搭建SSM spring springmvc mybatis整合的时候, 遇到了这个问题 说说我的问题吧!我在进行单元测试的时候,出现了这个错误,网上一查才知道是,配置文件中没有写扫描包信息.一看 ...
- 【java异常】expected at least 1 bean which qualifies as autowire candidate for this depende
1.查看接口实现类是否加入注解,如service.repository等 2.查看spring配置文件是否自动扫描包 <context:component-scan base-packag ...
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.oskyhang.gbd.service.UserService] found for dependency: expected at least 1 bean which qualifies as aut
spring中一个符号的错误居然让我浪费了四五个小时才找出来,不得不给自己了两个耳光.. 由于新建项目与原来项目的目录结构有所不同,copy过来的配置文件,有些地方修改的不彻底,导致spring扫描注 ...
- Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.thinkplatform.dao.UserLogDao' available: expected at least 1 bean which qualifies as autowi
我出错的问题是: 检查:
随机推荐
- webpack打包学习
从上图我们可以看出,webpack 可以将多种静态资源 js.css.sass文件等转换成一个静态文件,以此可以减少页面的请求,从而提高浏览器响应速度 1.安装开发依赖包 npm install we ...
- python---选择排序的实现
选择排序 思想 一趟遍历记录最小的数, 放到第一个位置 再一趟遍历记录剩余列表中最小的数, 继续放置 关键点: 无序区: 第i趟, 无序区为 i~n-1 最小数的位置 import r ...
- 在 Docker 上快速运行 Apache Airflow 2.2.4
Docker 安装 Apache Airflow 参考资料 Running Airflow in Docker 安装依赖 Docker Engine Docker Composite 快速运行 Apa ...
- For-Each循环(增强型For循环)
public class Demo077 { public static void main(String[] args) { int[] array ={11,2}; System.out.prin ...
- [转载] Golang交叉编译(跨平台编译)简述
一.何为交叉编译 简单地说,就是在一个平台上生成另一个平台上的可执行代码.同一个体系结构可以运行不同的操作系统:同样,同一个操作系统也可以在不同的体系结构上运行. 二.交叉编译前的准备 本文只介绍Wi ...
- Windows下查找各类游戏存档路径
我算是个比较爱打单机游戏的人,同时也是个半吊子的编程爱好者,有的时候会去干一些修改存档的事儿.不过这篇博文不讲存档修改技术,只讲第一步:去哪找存档? 目标:在windows10系统下搜索到游戏的存档路 ...
- Linux-I/O模型详解
I/O介绍 I/O通常有内存IO.网络I/O.磁盘I/O等,但我们通常说的是网络I/O以及磁盘I/O.网络I/O:本质是socket读取 每次I/O请求,都会有两个阶段组成: 第一步:等待数据,即数据 ...
- 蓝桥杯Web练习题:多个斜线开始的路径重定向问题
多个斜线开始的路径重定向问题 需求说明 在 vue-router v3.5.2 版本代码中存在一个 Bug,一个以多个斜线(///)开始的路径实际上可能会重定向到另一个域.这是因为 cleanPath ...
- 三大特性,多个场景,Serverless 应用引擎 SAE 全面升级
作者:营火 微服务能力大提升,更新增 Job.PHP 等场景,延展 Serverless 新边界 点击此处,获得阿里云 SAE 发布会直播 PPT! 企业的数字化随着互联网的普及发展越来越快,技术架构 ...
- C# 通关手册(持续更新......)
String 常用静态方法 string.Compare(string str1,string str2,bool ignoreCase) 按照字典顺序比较字符串 当str1 > str2时,返 ...