解决方案 --[restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :

简介: Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. ERROR 9680 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter

问题描述:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

ERROR 9680 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter  

问题分析

这个问题在网上找到很多方法,多半都是删除某某依赖,或者更改依赖版本,或者添加:(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})

但是笔者使用上述方法后仍然不管用,依然存在这个问题。

在这上面debug弄了一个小时,这时候,终于想起来看看IDEA的错误提示

给的提示是:

Description:

Field userRepository in com.example.usermanag.service.UserServiceImp required a bean of type

'com.example.usermanag.repository.UserRepository' 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.example.usermanag.repository.UserRepository' in your configuration.

仔细阅读,可以发现关键在The injection point has the following annotations:  @org.springframework.beans.factory.annotation.Autowired(required=true)这句话。

笔者回溯代码时才发现有个地方用了@Autowired 进行自动注入,查阅官方文档和其他博客,发现错误的原因在于:

spring framerwork 4.0以后就不推荐使用属性注入,改为推荐构造器注入和setter注入,因为属性注入方式容易出现循环依赖问题,即A注入B,B注入C,C注入A,这种情况很容易会报异常。

# 解决方案

法一:将@Autowired 改为 @Qualifier 进行注入

法二:将@Autowired 改为setter方式注入

法三:老老实实new对象,不使用自动注入

法四:应该还是可以继续以另外的方式使用@Autowired(这点暂时笔者也不会,等待各位补充)

类似错误但是是其他问题:请一定要看错误信息

相关文章
|
消息中间件 Java 数据库连接
JMS 消息队列接口基本使用指南
JMS 消息队列接口基本使用指南
1375 0
|
9月前
|
NoSQL 关系型数据库 MySQL
分布式锁:底层原理全拆解 + 高可用方案深度对比,生产落地全指南
本文系统解析分布式锁的必要性、八大核心设计准则,并对比MySQL、Redis原生、Redisson、ZooKeeper、Etcd五种主流方案,涵盖原理、代码实现、优缺点及生产选型指南,助你规避超时、误释放、脑裂等典型坑点。
675 1
|
Java API
详细解释一下Stream API中的sorted操作
详细解释一下Stream API中的sorted操作
990 1
|
Java
SpringBoot注入出现@org.springframework.beans.factory.annotation.Autowired(required=true)
SpringBoot注入出现@org.springframework.beans.factory.annotation.Autowired(required=true)
642 0
|
存储 前端开发 Java
springboot文件上传和下载接口的简单思路
本文介绍了在Spring Boot中实现文件上传和下载接口的简单思路。文件上传通过`MultipartFile`对象获取前端传递的文件并存储,返回对外访问路径;文件下载通过文件的uuid名称读取文件,并通过流的方式输出,实现文件下载功能。
springboot文件上传和下载接口的简单思路
|
Java Spring 容器
springboot 静态方法中使用@Autowired注入配置和Bean
springboot 静态方法中使用@Autowired注入配置和Bean
|
Web App开发 前端开发 JavaScript
如何去掉溢出内容的overflow属性滚动条
如何去掉溢出内容的overflow属性滚动条
1446 1
|
Java Spring
spring 使用遇到的问题
spring 使用遇到的问题
556 0
|
人工智能 Java 测试技术
解决SpringBoot 测试类无法自动注入@Autowired的问题
解决SpringBoot 测试类无法自动注入@Autowired的问题

热门文章

最新文章