SpringBoot项目意外出现 循环依赖和注入的对象意外是Null的问题 Requested bean is currently in creation: Is there an unresolvable circular reference? 或 nested exception is java.lang.NullPointerException
1.Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mybatisPlusConfig': Invocation of init method failed; nested exception is java.lang.NullPointerException
2.Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
以上2个情况均是指 迫切的注入依赖 导致
出现上面2种情况,无非就是启动时通过注入的Mapper或Service对象去初始化数据;前提是项目是真的没有循环依赖的情况下..
我这边的情况是 @Service接口和使用均没有手动声明循环依赖;排查了半天,只能妥协了;从代码里没有找到循环依赖的地方,想来可能是CGlib和JDK代理的时候导致的问题吧
通过 setMethod进行注入依然失败:Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
@Autowired
public void setSysDatabaseService(ISysDatabaseService sysDatabaseService)
第一种解决方法就是:使用以下语句在项目启动后进行初始化数据,执行的时机可以通过 org.springframework.boot.SpringApplication#run(java.lang.String...) 看到

@Bean
// public ApplicationRunner initIgnoreTenantTables(ISysDatabaseTenantService sysDatabaseTenantService){
// return args -> {
// // 启动时初始化无租户的列表
// List<String> notTenantTableNameList = sysDatabaseTenantService.findAllNotTenantTable().stream().map(SysDatabaseTenant::getTableName).collect(Collectors.toList());
// ignoreTenantTables.addAll(notTenantTableNameList);
// };
// }

经实验,加 @Lazy注解无法应用到这个场景里;无法有效的解决此问题
我出现这个问题的位置是:
@Configuration
// @Configuration(proxyBeanMethods = false)
class AConfig { // Service是正常的结构,没有任何问题;在Controller层调用均没有问题;出现这个的原因,可能就是 急切 加载导致的 private XXXService xxxService; @PostConstruct // 无效
public void init(){
xxxService.myMethod1();
} @Autowired
@Lazy
public void setXXXService(){ // 无效
xxxService.myMethod1();
} @Bean // 有效
public ApplicationRunner initIgnoreTenantTables(ISysDatabaseTenantService sysDatabaseTenantService){
return args -> {
xxxService.myMethod1();
};
} }
抛异常的位置:
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.AutowiredFieldElement#inject

org.springframework.beans.factory.support.DefaultListableBeanFactory#resolveDependency ;这里进行抛异常的,具体位置忘了,有大能知道原因,麻烦告知下

SpringBoot项目意外出现 循环依赖和注入的对象意外是Null的问题 Requested bean is currently in creation: Is there an unresolvable circular reference? 或 nested exception is java.lang.NullPointerException的更多相关文章
- Spirng 循环依赖报错:Requested bean is currently in creation: Is there an unresolvable circular reference?
1:前言 最近在项目中遇到了一次循环依赖报错的问题,虽然解决的很快,但是有些不明白的地方,特此记录. 在此我把 bean 的结构和 注入方式单独拎出来进行演示 1.1:报错提示 1.2:错误日志 Ex ...
- springboot 异常: Requested bean is currently in creation: Is there an unresolvable circular reference?
2018-07-31 11:56:18.812 WARN 10316 --- [ main] ConfigServletWebServerApplicationContext : Exception ...
- ?--Porg.springframework.beans.MethodInvocationException: Property 'username' threw exception; nested exception is java.lang.NullPointerException
使用BoneCP作为连接池,在启动Tomcat报出以下异常: 一月 02, 2016 2:12:17 下午 org.apache.tomcat.util.digester.SetPropertiesR ...
- HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException
HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException type ...
- 14- Servlet.service() for servlet [mvc-dispatcher] in context with path [/collegeservice] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root caus
有的service没有依赖注入:
- error:org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
问题:调用的方法在一个接口类中,但我并没有注入那个被调用的类 解决:在UserEntity前加上@Autowired @Controller public class MainController { ...
- SpringBoot项目启动org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException解决方法
将Pom文件中的SpringBoot版本调低即可. 我的是调成了2.5.6
- 报错:严重: Servlet.service() for servlet [springmvc] in context with path [ ] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
解决:service类或dao类需要@Autowired
- SSM框架报HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException错
如下图 一番排查之后发现原来是server层写漏注释了 粗心大意,一天内出现两次写漏注释,SSM框架有意思.
随机推荐
- zabbix监控多个nginx vhost网站状态码
需求 假设一台服务器运行了N个vhost网站,如何确定在大流量并发时候找到是哪个网站的问题呢? 这似乎是每个运维都会遇到的问题,方法有很多比如:1.看nginx日志大小确定访问量.2.通过前端代理确定 ...
- [数分笔记]Dedekind切割定理的证明
1.定理内容 Dedekind切割定理:设是实数集的一个切割,则或者有最大数,或者有最小数. 2.证明过程 设是中所有有理数所构成的集合,是中所有有理数所构成的集合 从而构成一个有理数集的切割 有三种 ...
- 思迈特软件Smartbi发展再提速,完成B+轮过亿战略融资
2021年4月,思迈特软件(Smartbi)宣布完成亿级B+轮战略融资,本轮投资方为领先的全球企业级数据分析和组织智能服务平台提供商--明略科技.此前,思迈特软件曾先后获得来自价值资本.方广资本的数千 ...
- mysql 语句的使用
查看数据库 show databases; use 数据库名: show tables; //显示数据库的表名describe 表名; //显示某表的字段, 建表模板 这是为了清楚直观,再mysql行 ...
- MySQL[练习|面试题]-我的租房网
1 # 创建数据库 2 CREATE DATABASE Tenement; 3 4 # 切换数据库 5 USE Tenement; 6 # 创建客户信息表 sys_user 7 CREATE TABL ...
- Tableau学习step1一Tableau概述
本文首发于博客冰山一树Sankey,去博客浏览效果更好. 一.Tableau优缺点 优点 ·简单易用,只要是会用 EXCEL,几分钟就可掌握 Tableau的基本用法 急速高效 ·结果美观 ·轻松整合 ...
- WPF优秀组件推荐之Stylet(二)
上一篇文章介绍了Stylet的一些基本功能,本篇将介绍一些深入一点的功能. 依赖注入 在Bootstrapper 类中注入需要的对象: public class Bootstrapper : Boot ...
- 04-SpringMVC之请求处理流程
SpringMVC之请求处理流程 我们知道DispatcherServlet就是一个HttpServlet,而HttpServlet的请求就从doGet/doPost开始 DispatcherServ ...
- vue监听有无网络
mounted () { window.addEventListener('offline', function ($event) { alert('offline'); }); wi ...
- Dubbo是什么?核心总结
Dubbo --是SOA架构的具体的实现框架! 2.1 Dubbo简介 Apache Dubbo是一款高性能的Java RPC框架.官网地址:[http://dubbo.apache.org] dub ...