简体   繁体   English

Spring Data JPA:Spring in Action的示例不运行

[英]Spring Data JPA: Example from Spring in Action don't run

I try to start an example from Spring in action 5. STS shows me the error: 我尝试从动作中的Spring开始一个例子.STS向我显示错误:

Error starting ApplicationContext. 启动ApplicationContext时出错。 To display the conditions report re-run your application with 'debug' enabled. 要显示条件报告,请在启用“debug”的情况下重新运行应用程序。 2019-06-24 10:47:06.472 ERROR 6300 --- [ restartedMain] osboot.SpringApplication 2019-06-24 10:47:06.472 ERROR 6300 --- [restartedMain] osboot.SpringApplication
: Application run failed :应用程序运行失败

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; org.springframework.beans.factory.BeanCreationException:在类路径资源[org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaConfiguration.class]中定义名称为'entityManagerFactory'的bean创建错误:init方法的调用失败; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; 嵌套异常是javax.persistence.PersistenceException:[PersistenceUnit:default]无法构建Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister 嵌套异常是org.hibernate.MappingException:无法获取org.hibernate.persister.entity.SingleTableEntityPersister的构造函数

This's example may receive there: GitHub - Spring in action: Spring Data JPA 这个例子可能会在那里收到: GitHub - Spring in action:Spring Data JPA

Can you help me? 你能帮助我吗? If need yet codes from example, I can copy here. 如果需要来自示例的代码,我可以在这里复制。

This example does not run with Java > 8. 此示例不使用Java> 8运行。

You have to use Java 8 to run it as it is. 您必须使用Java 8按原样运行它。

Spring Boot 2.0.x does not support Java 11. Spring Boot 2.0.x不支持Java 11。

You should upgrade the example to 2.1.6 您应该将示例升级到2.1.6

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.6.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

I try to re-produce your error, I catch the same 我尝试重新产生你的错误,我也抓住了同样的错误

Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister 引起:org.hibernate.MappingException:无法获取org.hibernate.persister.entity.SingleTableEntityPersister的构造函数

I read comment Spring Data JPA: Example from Spring in Action don't run 我读了评论Spring Data JPA:Spring in Action的例子没有运行

Changing 更改

@NoArgsConstructor(access=AccessLevel.PRIVATE, force=true)

to

@NoArgsConstructor(access=AccessLevel.PUBLIC, force=true)

does not resolve problem. 不解决问题。 Keep it like original. 保持原样。

Solution: 解:

(1) I am using JDK 12. Add dependency (1)我正在使用JDK 12.添加依赖项

<!-- https://mvnrepository.com/artifact/org.javassist/javassist -->
<dependency>
    <groupId>org.javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.25.0-GA</version>
</dependency>

(2) Program argumnet (2)程序argumnet

--illegal-access=ignore

Result: In console log, applicaton run sucesss 结果:在控制台日志中,应用程序运行成功

Hibernate: insert into ingredient (name, type, id) values (?, ?, ?) Hibernate:插入成分(名称,类型,id)值(?,?,?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM