Spring Data Jpa Sping Boot 创建名为entityManagerFactory的Bean时出错

djmepvbi  于 2024-01-09  发布在  Spring
关注(0)|答案(1)|浏览(309)

我已经按如下所示设置了Spring应用程序,但它总是给我一个错误

  1. org.springframework.beans.factory.BeanCreationException:
  2. Error creating bean with name 'entityManagerFactory'
  3. defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/query/BindableType

字符串
这是一个基本的spring设置,没有任何类,只是配置

  1. plugins {
  2. java
  3. id("org.springframework.boot") version "2.7.15"
  4. id("io.spring.dependency-management") version "1.0.15.RELEASE"
  5. }
  6. group = "com.example"
  7. version = "0.0.1-SNAPSHOT"
  8. java {
  9. sourceCompatibility = JavaVersion.VERSION_17
  10. }
  11. repositories {
  12. mavenCentral()
  13. }
  14. dependencies {
  15. implementation("org.springframework.boot:spring-boot-starter-actuator")
  16. implementation("org.springframework.boot:spring-boot-starter-data-jpa")
  17. implementation("org.springframework.boot:spring-boot-starter-security")
  18. implementation("org.springframework.boot:spring-boot-starter-validation")
  19. implementation("org.springframework.boot:spring-boot-starter-web")
  20. testImplementation("org.springframework.boot:spring-boot-starter-test")
  21. testImplementation("org.springframework.security:spring-security-test")
  22. //DB
  23. implementation("org.postgresql:postgresql")
  24. implementation("org.liquibase:liquibase-core:4.23.1")
  25. implementation("com.vladmihalcea:hibernate-types-60:2.21.1")
  26. }
  27. tasks.withType<Test> {
  28. useJUnitPlatform()
  29. }


application.properties

  1. spring.main.banner-mode=off
  2. server.port=8090
  3. # For liquibase use
  4. spring.datasource.url=jdbc:postgresql://test.com:5432/main
  5. spring.jpa.hibernate.ddl-auto=
  6. spring.liquibase.enabled=false
  7. spring.liquibase.liquibase-schema=test
  8. # PostgreSQL
  9. spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
  10. spring.datasource.username=admin
  11. spring.datasource.password=xxx
  12. spring.jpa.properties.hibernate.default_schema=test

lx0bsm1f

lx0bsm1f1#

Sping Boot 2.7.15使用Hibernate 5.6.15.Final,因此您需要包含com.vladmihalcea:hibernate-types-55而不是com.vladmihalcea:hibernate-types-60。hibernate-types-60仅与Hibernate 6一起使用。BindableType是Hibernate 6类,在Hibernate 5中不存在。我猜hibernate-type-60使用BindableType类。
您可能希望迁移到hypersistence-utils-hibernate-55。有关您可能希望升级的原因的信息,请参阅this

相关问题