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的更多相关文章

  1. Spirng 循环依赖报错:Requested bean is currently in creation: Is there an unresolvable circular reference?

    1:前言 最近在项目中遇到了一次循环依赖报错的问题,虽然解决的很快,但是有些不明白的地方,特此记录. 在此我把 bean 的结构和 注入方式单独拎出来进行演示 1.1:报错提示 1.2:错误日志 Ex ...

  2. 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 ...

  3. ?--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 ...

  4. 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 ...

  5. 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没有依赖注入:

  6. error:org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException

    问题:调用的方法在一个接口类中,但我并没有注入那个被调用的类 解决:在UserEntity前加上@Autowired @Controller public class MainController { ...

  7. SpringBoot项目启动org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException解决方法

    将Pom文件中的SpringBoot版本调低即可. 我的是调成了2.5.6

  8. 报错:严重: 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

  9. SSM框架报HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException错

    如下图 一番排查之后发现原来是server层写漏注释了 粗心大意,一天内出现两次写漏注释,SSM框架有意思.

随机推荐

  1. VS Code 在线运行:code-server部署(系列一)

    偶然间发现VS Code可以在线运行,闲来无事部署了一套试试效果,先上图,是不是很熟悉的感觉,初步体验基本跟本地运行效果一样. 进入正题 首先要准备一套linux环境,环境配置最低是1G内存.2核CP ...

  2. curl的HTTP参数速查表

    curl简介 curl是一个开源的命令行工具,它基于网络协议,对指定URL进行网络传输,得到数据后不任何具体处理(如:html的渲染等),直接显示在"标准输出"(stdout)上. ...

  3. csaw密码

    题目:AAoHAR1TIiIkUFUjUFQgVyInVSVQJVFRUSNRX1YgXiJSVyJQVRs=写python脚本: import base64 ciphertext="AAo ...

  4. spring 核心容器api

    spring api : https://docs.spring.io/spring-framework/docs/current/javadoc-api/ BeanFactory 才是 Spring ...

  5. Linux的用户与用户组管理

    1.Linux用户与用户组 Linux 是多用户多任务操作系统,Linux 系统支持多个用户在同一时间内登陆,不同用户可以执行不同的任务,并且互不影响.不同用户具有不问的权限,毎个用户在权限允许的范围 ...

  6. Python第二

    今日内容概要 基本运算符 流程控制 字符编码 理论特别多.结论特别少 文件处理 今日内容详细 基本运算符 1.算数运算符 x = 1 y = 5 res = x + y #加 res1 = x - y ...

  7. (五)目标检测算法之Faster R-CNN

    系列博客链接: (一)目标检测概述 https://www.cnblogs.com/kongweisi/p/10894415.html (二)目标检测算法之R-CNN https://www.cnbl ...

  8. One-Hot编码(转)

    机器学习:数据预处理之独热编码(One-Hot) 前言 ---------------------------------------- 在机器学习算法中,我们经常会遇到分类特征,例如:人的性别有男女 ...

  9. JZ-049-把字符串转换成整数

    把字符串转换成整数 题目描述 将一个字符串转换成一个整数,要求不能使用字符串转换整数的库函数. 数值为0或者字符串不是一个合法的数值则返回0 输入描述: 输入一个字符串,包括数字字母符号,可以为空 返 ...

  10. 线上| 10万奖金!Greaterwms/DVAdmin插件开发者现金激励活动

    为激励广大开发者创作精神,Greaterwms/DVadmin插件开发者现金激励活动现已上线! 什么是GreaterWMS 完全开源仓储管理软件,遵循Apache License 2.0协议,前后端分 ...