解决方案 --[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(这点暂时笔者也不会,等待各位补充)

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

目录
打赏
0
0
0
0
70
分享
相关文章
163邮箱IMAP服务器设置方法
```markdown 使用IMAP协议同步163邮箱:登录邮箱→设置→账户→IMAP/SMTP→开启服务→配置服务器(imap.163.com:993, SSL/TLS)→设置用户名和密码→保存并在邮件客户端添加账号。确保多设备邮件同步,定期更新设置。[≤240字符] ```
Linux系统介绍
Linux系统介绍
691 2
CentOS 7- 配置阿里镜像源
阿里镜像官方地址http://mirrors.aliyun.com/ 1、点击官方提供的相应系统的帮助 :2、查看不同版本的系统操作: 下载源1、安装wget yum install -y wget2、下载CentOS 7的repo文件wget -O /etc/yum.
245621 0
搭建文生图AI系统
随着人工智能的发展,**文本生成图像(文生图)**技术在广告创意、视觉设计、内容营销等领域应用广泛。阿里云通义千问作为先进的大语言模型,不仅具备强大的文本理解能力,还能与图像生成技术结合,实现根据文本描述自动生成高质量图像。 本博客将展示如何使用通义千问与阿里云的其他产品(如函数计算、API 网关、对象存储 OSS)搭建一个简单的文生图系统,实现用户输入文本并生成相应图像的功能。
398 6
云计算的技术演变与未来趋势
【10月更文挑战第4天】云计算的技术演变与未来趋势
566 5
Spring Boot 启动错误:To display the conditions report re-run your application with ‘debug‘ enable —【已解决】
Spring Boot 启动错误:To display the conditions report re-run your application with ‘debug‘ enable —【已解决】
3643 1
已解决 IDEA Maven 项目中 “Could not find artifact“ 问题的常见情况和解决方案
已解决 IDEA Maven 项目中 “Could not find artifact“ 问题的常见情况和解决方案
13909 0
SpringBoot启动报错:Unable to start LiveReload server【已解决】
SpringBoot启动报错:Unable to start LiveReload server【已解决】
594 0
SpringBoot——聊聊application.properties和application.yml的写法规范及区别
SpringBoot——聊聊application.properties和application.yml的写法规范及区别
1015 0
SpringBoot——聊聊application.properties和application.yml的写法规范及区别
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问