-
BeanCurrentlyInCreationException sqlSessionFactory Requested bean is currently in creation: Is there
Springboot项目集成h2 databse遇到的异常
1.异常现象
Springboot集成h2 database,h2配置如下
spring.datasource.driver-class-name=org.h2.Driver spring.datasource.url=jdbc:h2:~/test spring.datasource.username=sa spring.datasource.password=sa spring.datasource.schema=classpath:db/*.sql spring.datasource.initialization-mode=always spring.datasource.continue-on-error=false spring.h2.console.path=/h2-console spring.h2.console.enabled=true
当spring.datasource.schema配置脚本时,就会抛出异常,具体异常信息为:
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?
如果不配置spring.datasource.schema的值,也就不会初始化数据库脚本,也不会抛异常。
2.问题解决
由于能力不足,在网上到处搜索,搜索了整整一天终于解决了。这个异常的原因看名字就能大致猜出来:Bean对象当前正在创建异常。
由于公司用的RPC框架的注解的类都有这个异常抛出,普通@Service类都可以正常注入Bean。所以可以断定是公司RPC框架注解的问题,不能在Bean完全创建好后再注入导致的问题。
解决办法就是在注入的属性上添加@Lazy注解,表示暂时不注入对象,等到调用该属性(接口)时再注入Bean。类似下方代码
@公司RPC @Service public class UserService{ @Lazy @Autowired private UserMapper userMapper; public User getById(String id){ return userMapper.getById(id); } }
原文:https://www.cnblogs.com/hdwang/p/14186467.html
最新更新
求1000阶乘的结果末尾有多少个0
详解MyBatis延迟加载是如何实现的
IDEA 控制台中文乱码4种解决方案
SpringBoot中版本兼容性处理的实现示例
Spring的IOC解决程序耦合的实现
详解Spring多数据源如何切换
Java报错:UnsupportedOperationException in Col
使用Spring Batch实现批处理任务的详细教程
java中怎么将多个音频文件拼接合成一个
SpringBoot整合ES多个精确值查询 terms功能实
数据库审计与智能监控:从日志分析到异
SQL Server 中的数据类型隐式转换问题
SQL Server中T-SQL 数据类型转换详解
sqlserver 数据类型转换小实验
SQL Server数据类型转换方法
SQL Server 2017无法连接到服务器的问题解决
SQLServer地址搜索性能优化
Sql Server查询性能优化之不可小觑的书签查
SQL Server数据库的高性能优化经验总结
SQL SERVER性能优化综述(很好的总结,不要错
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比