spring boot jar Initialized JPA EntityManagerFactory 失败【导致jar启动闪退】
Posted on 2023-06-10 21:43 且行且思 阅读(231) 评论(0) 编辑 收藏 举报2023-06-10 21:29:04.460 WARN 24060 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister 2023-06-10 21:29:04.468 INFO 24060 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closed 2023-06-10 21:29:04.509 INFO 24060 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
无法初始化 JPA EntityManagerFactory:无法创建请求的服务 [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
或者
Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
或
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/zero/xunwuproject/config/JpaConfig.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
这个错误有多种原因导致,在网上查了一下, 大概有以下几种原因:
-
实体类的属性对象没有设置setter或者getter。
-
没有导入javassist的jar文件 (javassist-3.15.0-GA.jar什么的)
http://blog.csdn.net/xiaochangwei789/article/details/7712725
- 实体类中的属性对象名和映射文件的property name不一致。
https://blog.csdn.net/liuzhengyang1/article/details/23127629
而我这里是第二个原因,缺少javassist的jar包,于是在pom文件中引入:
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.23.1-GA</version>
</dependency>
解决办法:缺少 javassist-3.15.0-GA.jar 包,版本未定。引入了这个jar包后,启动就正常了。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
2009-06-10 .net 接收存储过程的返回值 。。。。