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
我出错的问题是: 检查:
随机推荐
- 在容器使用stress指令进行负载压测
安装stressstress是一个linux下的压力测试工具,专门为那些想要测试自己的系统,完全高负荷和监督这些设备运行的用户 在容器中安装docker容器压测工具 stress #先安装一些基础工具 ...
- kubectl get node -n wide --show-labels
集群环境:1.k8s用的是二进制方式安装2.操作系统是linux (centos)3.操作系统版本为 7.4/7.94.k8s的应用管理.node管理.pod管理等用rancher.k8s令牌以及ma ...
- 『现学现忘』Git基础 — 2、Git和SVN的区别
1.Git和SVN的区别 (1)SVN(集中式版本管理系统) 集中式的版本控制系统都有一个单一的集中管理的服务器,保存所有文件的修订版本,而协同工作的人们都通过客户端连到这台服务器,取出最新的文件或者 ...
- python 面试题汇总
1丶元组(list)和列表(tuple)的区别: 一:共同点: ①: 可以放置任意数据类型的有序集合,都是可以存放数字,字符串,对象等. ②:都支持 负索引,切片,随意嵌套等操作 二:不同点: ①: ...
- 新手小白入门C语言第三章:关于数据类型
C 语言包含的数据类型 1.整型 整型分为整形常量和整形变量,常量就是我们平时所看到的准确的数字,例如:1.20.333等等,变量则按我的理解是我像内存去申请一个存储空间,告诉内存空间我申请了这个地方 ...
- 面试突击39:synchronized底层是如何实现的?
想了解 synchronized 是如何运行的?就要先搞清楚 synchronized 是如何实现? synchronized 同步锁是通过 JVM 内置的 Monitor 监视器实现的,而监视器又是 ...
- 2021.11.03 P2886 [USACO07NOV]Cow Relays G(矩阵+floyed)
2021.11.03 P2886 [USACO07NOV]Cow Relays G(矩阵+floyed) [P2886 USACO07NOV]Cow Relays G - 洛谷 | 计算机科学教育新生 ...
- 21天学通Python PDF完整版
有需要的点击这里自取 内容简介 · · · · · · <21天学通Python>全面.系统.深入地讲解了Python编程基础语法与高级应用.在讲解过程中,通过大量实际操作的实例将Pyt ...
- Python常用数据结构-字典——2.1 字典方法 keys()
python字典常用方法: keys() # 获取所有的键 values() # 获取所有的值 items() # 获 ...
- 百度SEO算法技术的局限性,怎么做才能有收益
不知道大家有没有发现,我们使用百度的频率在减少,就算有时遇到一些问题,需要用百度来寻找答案,也会经常遇到搜索不到答案的情况.到底是出了什么问题?难道网络上的资源不够丰富了?浩如烟海的互联网,居然搜索不 ...