You need to enable JavaScript to run this app. Spring Boot 2.3.4整合Spring Data JPA启动报错无法定位根因求助
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 2.3.4整合Spring Data JPA启动报错无法定位根因求助

问题背景

基于 Spring Boot 2.3.4 版本、结合 Spring Data JPA 开发的应用,在启动过程中抛出异常,现有日志片段无法定位错误根因,请求协助排查。

收集到的日志片段

Hibernate 初始化阶段日志

{"timestamp": "12/21/2020 18:52:02:0871", "class": "org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator", "file": "JtaPlatformInitiator.java", "level" : " INFO", "line_number" : "52", "url": "", "ip_address": "", "server_trace_id":"", "message": "HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]", "method": "initiateService", "thread_name": "task-1"}
{"timestamp": "12/21/2020 18:52:02:0872", "class": "org.hibernate.query.spi.NamedQueryRepository", "file": "NamedQueryRepository.java", "level" : "DEBUG", "line_number" : "151", "url": "", "ip_address": "", "server_trace_id":"", "message": "Checking 0 named HQL queries", "method": "checkNamedQueries", "thread_name": "task-1"}
{"timestamp": "12/21/2020 18:52:02:0872", "class": "org.hibernate.query.spi.NamedQueryRepository", "file": "NamedQueryRepository.java", "level" : "DEBUG", "line_number" : "167", "url": "", "ip_address": "", "server_trace_id":"", "message": "Checking 0 named SQL queries", "method": "checkNamedQueries", "thread_name": "task-1"}
{"timestamp": "12/21/2020 18:52:02:0891", "class": "org.hibernate.internal.SessionFactoryRegistry", "file": "SessionFactoryRegistry.java", "level" : "DEBUG", "line_number" : "52", "url": "", "ip_address": "", "server_trace_id":"", "message": "Initializing SessionFactoryRegistry : org.hibernate.internal.SessionFactoryRegistry@263b5690", "method": "<init>", "thread_name": "task-1"}
{"timestamp": "12/21/2020 18:52:02:0891", "class": "org.hibernate.internal.SessionFactoryRegistry", "file": "SessionFactoryRegistry.java", "level" : "DEBUG", "line_number" : "74", "url": "", "ip_address": "", "server_trace_id":"", "message": "Registering SessionFactory: 64cd8993-8947-4c28-8a99-8717be785280 (<unnamed>)", "method": "addSessionFactory", "thread_name": "task-1"}
{"timestamp": "12/21/2020 18:52:02:0891", "class": "org.hibernate.internal.SessionFactoryRegistry", "file": "SessionFactoryRegistry.java", "level" : "DEBUG", "line_number" : "81", "url": "", "ip_address": "", "server_trace_id":"", "message": "Not binding SessionFactory to JNDI, no JNDI name configured", "method": "addSessionFactory", "thread_name": "task-1"}
{"timestamp": "12/21/2020 18:52:02:0896", "class": "org.hibernate.internal.SessionFactoryImpl", "file": "SessionFactoryImpl.java", "level" : "DEBUG", "line_number" : "771", "url": "", "ip_address": "", "server_trace_id":"", "message": "HHH000031: Closing", "method": "close", "thread_name": "restartedMain"}
{"timestamp": "12/21/2020 18:52:02:0897", "class": "org.hibernate.type.spi.TypeConfiguration$Scope", "file": "TypeConfiguration.java", "level" : "DEBUG", "line_number" : "350", "url": "", "ip_address": "", "server_trace_id":"", "message": "Un-scoping TypeConfiguration [org.hibernate.type.spi.TypeConfiguration$Scope@3fbaa2e9] from SessionFactory [org.hibernate.internal.SessionFactoryImpl@1741883a]", "method": "unsetSessionFactory", "thread_name": "restartedMain"}
{"timestamp": "12/21/2020 18:52:02:0902", "class": "org.hibernate.service.internal.AbstractServiceRegistryImpl", "file": "AbstractServiceRegistryImpl.java", "level" : "DEBUG", "line_number" : "419", "url": "", "ip_address": "", "server_trace_id":"", "message": "Implicitly destroying ServiceRegistry on de-registration of all child ServiceRegistries", "method": "deRegisterChild", "thread_name": "restartedMain"}
{"timestamp": "12/21/2020 18:52:02:0902", "class": "org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl", "file": "BootstrapServiceRegistryImpl.java", "level" : "DEBUG", "line_number" : "295", "url": "", "ip_address": "", "server_trace_id":"", "message": "Implicitly destroying Boot-strap registry on de-registration of all child ServiceRegistries", "method": "deRegisterChild", "thread_name": "restartedMain"}

异常堆栈

Exception in thread "task-2" org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'delegatingApplicationListener': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:245)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:197)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:134)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361)
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.publishEventIfRequired(DataSourceInitializedPublisher.java:99)
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.access$100(DataSourceInitializedPublisher.java:50)
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher$DataSourceSchemaCreatedPublisher.lambda$postProcessEntityManagerFactory$0(DataSourceInitializedPublisher.java:200)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:832)

数据源关闭日志

{"timestamp": "12/21/2020 18:52:02:0905", "class": "com.zaxxer.hikari.HikariDataSource", "file": "HikariDataSource.java", "level" : " INFO", "line_number" : "350", "url": "", "ip_address": "", "server_trace_id":"", "message": "HikariPool-1 - Shutdown initiated...", "method": "close", "thread_name": "restartedMain"}
{"timestamp": "12/21/2020 18:52:02:0906", "class": "com.zaxxer.hikari.pool.HikariPool", "file": "HikariPool.java", "level" : "DEBUG", "line_number" : "421", "url": "", "ip_address": "", "server_trace_id":"", "message": "HikariPool-1 - Before shutdown stats (total=1, active=0, idle=1, waiting=0)", "method": "logPoolState", "thread_name": "restartedMain"}
异常链路说明
  • 日志中展示的BeanCreationNotAllowedException属于启动流程终止后的次生异常,不是引发启动失败的根本原因。
  • 次生异常的触发逻辑:
    1. 启动过程中因某类根因错误触发应用上下文销毁流程,主线程restartedMain开始依次关闭Hibernate SessionFactory、注销服务注册表、发起Hikari连接池关闭操作
    2. 此前提交的异步工作线程task-2仍在执行JPA模块的数据源初始化完成事件发布逻辑,尝试从Bean工厂中获取应用监听器实例
    3. 此时Bean工厂已进入销毁阶段,禁止获取/创建单例Bean,因此抛出该异常
排查指引
  • 当前提供的日志存在截断,根因信息出现在HHH000031: Closing这条Hibernate SessionFactory关闭日志之前的位置,需要补全该段时间窗口内的ERROR/WARN级别日志内容
  • Spring Boot 2.3.4 + Spring Data JPA 组合下,常见的启动失败触发点包括:
    • JPA实体类注解配置错误,存在实体属性与数据库字段映射冲突、命名策略不兼容问题
    • 数据库连接参数配置错误,包含连接地址、账号密码、库访问权限不匹配
    • 依赖版本冲突,引入的Hibernate版本与Spring Boot 2.3.4 管理的默认版本不兼容
    • 启动阶段执行的初始化SQL脚本存在语法错误、表结构不匹配问题
  • 定位根因的核心技巧:优先筛选restartedMain主线程的日志,找到该线程抛出的第一处ERROR级别堆栈,即为真正的启动失败原因。

内容的提问来源于stack exchange,提问作者CHiRAG

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.11 23:15:03