o.s.b.d.LoggingFailureAnalysisReporter 错误解决方法

项目场景:

JPA学习场景出现的bug


问题描述

问题:2022-08-06 21:24:56.270 ERROR 8784 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   :


原因分析:

仔细阅读,可以发现关键在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,这种情况很容易会报异常


解决方案:

在SpringBootApplication增加注解@ComponentScan(basePackages = {"com.how2java.springboot.dao"})

方法一:在你的主类中找到@SpringBootApplication,在其后面添加(exclude = {DataSourceAutoConfiguration.class})然后保存。

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

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

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

借鉴:

解决方案 --[restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :_中杯可乐多加冰的博客-CSDN博客


版权声明:本文为lifuran156原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。