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. libc++abi.dylib: terminating with uncaught exception of type NSException

    这是微信sdk注册时候报的错误 解决方法 选择Build Setting,在"Other Linker Flags"中加入"-Objc -all_load"

  2. CobaltStrike逆向学习系列(2):Stageless Beacon 生成流程分析

    这是[信安成长计划]的第 2 篇文章 关注微信公众号 [信安成长计划] 0x00 目录 0x01 Patch Beacon 0x02 Patch Loader 0x03 文件对比 0x04 流程图 C ...

  3. Spring-servlet随笔1

    一:工程思想 1.建立父工程 2:导入通用依赖 3:删除无用文件 4:创建不同模块. pom.xml 依赖文件: <dependencies>   <dependency>   ...

  4. 攻防世界-Crypto高手进阶区部分Writeup

    1.flag_in_your_hand && flag_in_your_hand1 下载,解压后 打开index文件,直接点击get flag错误,输入其他点击也同样 打开js文件,在 ...

  5. 大数据分析用自助式BI工具就能轻松解决,so easy!

    之前老板给了我一个任务,让我赶紧学习一下大数据分析,下个季度就要用. 赶紧看了一下日历,这离下个季度还有不到半个月的时间,而且我还没有数据分析基础,该怎么能在这么短的时间内学会大数据分析呢-- 经过多 ...

  6. 国产BI报表工具中低调的优秀“模范生”——思迈特软件Smartbi

    首先简单来介绍一下这位低调且优秀的模范生--思迈特软件Smartbi.思迈特Smartbi是企业级商业智能BI和大数据分析品牌,满足用户在企业级报表.数据可视化分析.自助分析平台.数据挖掘建模.AI智 ...

  7. Smartbi扩展性怎么样,是否方便扩展开发产品已有功能?

    Smartbi大数据分析工具具有很强的扩展性,通过"稳定内核+API扩展"的架构,通过报表插件扩展的方式,能满足很多应用项目的定制化需求,把新功能无缝集成到系统中. Smartbi ...

  8. 重点收藏!BI数据分析工具哪家强?

    信息爆炸时代,大数据晋升为一个时髦词汇.不论是在哪个行业领域,大数据分析成为各企业备受推崇的决策工具.对于海量数据的挖掘,有助于统计事情发生的概率,帮助人们计算做某些事情成功的几率.企业正在数据的海洋 ...

  9. 为什么DRAM采用地址复用技术?为什么SRAM不采用地址复用技术?

    行列地址复用:比如你的存储器容量是16bit,那么可以将这16个比特组织成一个4*4的矩阵,为了找到某个你想要找的bit,比如第1行第2列的那个bit.你先发送二进制的01,表示要找的数据在第1行:接 ...

  10. Oracle之查询排序

    SQL排序查询 DESC降序.ASC升序(默认是升序) /* 语法结构: SELECT * | 列名1[,列名2...] | 表达式 FROM 表名 [WHERE 限定条件] ORDER BY 列名1 ...