异常处理(二)---------Field * in * required a bean of type '*' that could not be found.
昨天在做SB项目整合Redis的时候报了这个错误。
以下是这个异常的完整信息
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-12-13 16:11:39.632 ERROR 3660 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter : ***************************
APPLICATION FAILED TO START
***************************Description:Field redisUtil in cn.yzstu.baldwinblog.controller.UserController required a bean of type 'cn.yzstu.common.utils.redis.RedisUtil' 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 'cn.yzstu.common.utils.redis.RedisUtil' in your configuration.
redisUtil:Controller中Autowire的一个Redis工具类
cn.yzstu.baldwinblog.controller.UserController:该Controller
ResultUtil:有关该类的信息如下
根据英文的提示是在配置中找不到一个指定自动注入类型的bean,经过多方排查得出结论:
正常情况下加上@Component(@Configuration注解包含了@Component注解功能)注解的类会自动被Spring扫描到生成Bean注册到spring容器中,既然他说没找到,也就是该注解被没有被spring识别,问题的核心关键就在application类的注解SpringBootApplication上 ,结合前几天遇到的扫描不到Mapper的问题思考,我感觉问题就是:我们本应设置我们应该扫描的文件夹,但是却没有设置。
然后我就想到了@ComponentScan注解,其实我们一般练手SB项目不会用到这个注解,因为启动类application.java中存在@SpringBootApplication时,spring会自动扫描当前包及当前包的各级子包,但是大家可以回头看一下我的@Bean注解的redisUtil的位置,是不在启动文件关联包下的,所以这时spring就扫描不到RedisUtil了。
解决办法:
不推荐使用我这种注解方法,直接扫描所有包,会影响项目启动时的加载速度
更多关于@Component注解的内容,可以自己去查一下
异常处理(二)---------Field * in * required a bean of type '*' that could not be found.相关推荐
- field xinx required a bean of type x that could not be found
以上是我代码启动时报的错. 报错原因:spring项目启动时没有扫描到该bean, 解决方式2种: 第一种:按照项目包的接口放service和serviceImpl层,springboot项目启动类包 ...
- SpringBoot 报错Field XXX required a bean of type XXX that could not be found.
场景 SpringBoot项目运行时提示: 解决 首先查看service下是否有@Service注解 这里有. 然后找到启动类 修改前: 修改后: 添加: @SpringBootApplication ...
- 【踩坑专栏】Field XXX required a bean of type ‘xx.xx.XXX‘ that could not be found.
报错说找不到的类已经标注上@Component等注解了,但是idea会警告你说没注入,编译没报错,启动报错说找不到这个类. 我出现此问题的原因是没有在启动类上指定包路径,指定一下包路径就好了 @Spr ...
- springboot 启动报错Field XXX required a bean of type XXX that could not be found的解决方案总结
1.检查 各个层的注解,尤其是Mapper层,看是否遗漏 @Mapper/@Repository 2.检查启动类注解,如若没问题,可加 @ComponentScan("需要扫描的包路径&qu ...
- 报错Field Mapper in xxx.xxxServiceImpl required a bean of type ‘dao.xxxMapper‘ that could not be found
报错Field Mapper in xxx.xxxServiceImpl required a bean of type 'dao.xxxMapper' that could not be found ...
- Field testMapper in com.example.demo.service.TestService required a bean of type ‘com.example.demo.m
由于解决过程太漫长,直接给出解决方案: 原因mybatis的jar包导错了!Mapper接口类上使用了注解@Mapper,根据intellij idea提示引入了依赖: <dependency& ...
- Field XXXService in com.XXX.controller.XXX required a bean of type ‘com.XXX.mapper.xxx‘that could no
解决办法: Field surveyTypeService in com.XXX.controller.XXX required a bean of type 'com.XXX.mapper.xxx' ...
- Field userInfoMapper in com.example.test.service.impl.UserServiceImpl required a bean of type ‘com.
Field userInfoMapper in com.example.test.service.impl.UserServiceImpl required a bean of type 'com.e ...
- springboot Field userInfoInter in com.**.** required a bean of type ‘***.**‘
问题: Field userInfoInter in com.yyjc.springboot.service.UserInfoService required a bean of type 'com. ...
- 解决:Field xxMapper in xx.service.impl.xxServiceImpl required a bean of type ‘xx.mapper.xxMapper‘
前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 1. 启动 springboot 项目报错: Field userMapper in gentle. ...
最新文章
- 使用机器学习方法预测IBM员工流失数据模型
- MATLAB从入门到精通:基本矩阵运算-矩阵的基本方法和函数
- 【Java算法】一天24小时中,时针和分针一共重合多少次?
- 如何设计大型游戏服务器架构?
- kafka消费者分区的分配的三种机制
- 基于Linux的USB主/从设备之间的三种通信方式-转
- C++里面的LPBYTE是什么意思
- SQL注入:SQL注入防御
- 计算机显示无法格式化,电脑提示windows无法完成格式化怎么办
- 2030中国足球称霸世界
- SpringCloud优点、缺点
- Hbase的scan原理
- 2019 原创技术干货整理
- 计算机网络和办公室自动化设备管理,通讯、计算机信息(含互联网)及办公自动化设备的安全保密管理暂行规定...
- OpenCV视频篇——从.JPG到.AVI:视频编码最强入门科普
- 高效学习 程序员练级攻略
- RPC常用消息中间件
- 新零售模式|传统零售企业向智慧零售转型的创新之路
- 嵌入式之根文件系统原理学习笔记
- spring boot关闭actuator路径
热门文章
- fastlane php,fastlane 自动化打包不同的target,以及手动传版本号参数
- win7未能成功安装驱动服务器,ghost win7未能成功安装设备驱动程序怎么办解决方法...
- java中Decimal 小数和百分比的转换
- colab运行在本地
- Unity中使用的四种存档和读档方式
- 程序员进阶必看!Java进阶书籍推荐
- 数据分析新人如何面对繁杂且突然的数据需求
- 2020家用千兆路由器哪款好_家用千兆路由器哪款好(2020年千兆路由器排行榜)...
- 计算机桌面备份在哪里,电脑备份文件在哪里
- CUDA11.1安装AlphaPose