Spring Boot 3 升级错误:org.hibernate.annotations.Type 缺少元素值

问题描述 投票:0回答:1

我最近开始将 Spring Boot 应用程序从 2.2.4.RELEASE 升级到 3.0.0

虽然我想认为到目前为止我在解决升级问题方面做得很好,但这个问题已经阻止了我很长一段时间。

但是,该项目构建没有任何问题。当我触发测试套件时遇到错误

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: org.hibernate.annotations.Type missing element value

    Caused by: java.lang.annotation.IncompleteAnnotationException: org.hibernate.annotations.Type missing element value
        at java.base/sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:86)

我什至在测试类中没有任何@Type注释,所以我很困惑。

上述错误是由我的所有测试产生的,产生错误的示例测试如下:

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

import com.getyourguide.pricingalerts.Application;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class HomeEndpointsTest {
    @Test
    public void testReadiness() throws Exception {
        String response = "Ha";

        assertThat(response, is("Ok"));
    }

如果删除 @RunWith(SpringRunner.class) 或 @SpringBootTest(classes = Application.class) 中的任何一个,测试将按预期工作。只有当两者同时使用时才会出现错误。

我的build.gradle包含以下依赖项

dependencies {
    // https://mvnrepository.com/artifact/com.google.api-client/google-api-client-gson
    implementation 'com.google.api-client:google-api-client-gson:2.2.0'
    implementation 'org.springframework.boot:spring-boot-starter-validation:3.0.5'

    implementation 'org.springframework.boot:spring-boot-starter-data-jpa:3.0.5'
    annotationProcessor 'org.hibernate:hibernate-core-jakarta:5.6.15.Final'


    implementation 'javax.validation:validation-api:2.0.1.Final'

    implementation group: 'jakarta.xml.bind', name: 'jakarta.xml.bind-api', version: '4.0.0'
    implementation group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '4.0.1'
    implementation group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '4.0.2'


    // Spring MVC, testing, and devtools
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'

    // https://mvnrepository.com/artifact/io.netty/netty-transport
    implementation group: 'io.netty', name: 'netty-transport-native-epoll', version: '4.1.90.Final', classifier: 'linux-x86_64'
    implementation 'junit:junit:4.13.2'


    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'io.projectreactor:reactor-test'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    // Lombok annotations to reduce boilerplate code
    compileOnly 'org.projectlombok:lombok:1.18.26'
    annotationProcessor 'org.projectlombok:lombok:1.18.26'
    // create MetaModel for jpa specification/
    annotationProcessor 'org.hibernate:hibernate-jpamodelgen:6.1.7.Final'
    implementation 'io.hypersistence:hypersistence-utils-hibernate-60:3.3.0'

    // Sentry
    implementation 'io.sentry:sentry-spring-boot-starter-jakarta:6.16.0'
    implementation 'io.sentry:sentry-logback:6.16.0'

    // DataDog
    datadogAgent group: 'com.datadoghq', name: 'dd-java-agent', version: '1.10.0'
    implementation group: 'com.datadoghq', name: 'dd-trace-api', version: '1.10.0'
    implementation 'com.datadoghq:java-dogstatsd-client:4.2.0'
    implementation 'io.micrometer:micrometer-registry-statsd:1.10.5'
    // Error Prone: (java error/antipattern checker - works with the net.ltgt.errorprone plugin above)
    errorprone 'com.google.errorprone:error_prone_core:2.18.0'
    // Database support
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    testImplementation 'net.ttddyy:datasource-proxy:1.8'
    // MySQL
    implementation 'org.mariadb.jdbc:mariadb-java-client:3.1.2'
    implementation 'com.h2database:h2:2.1.214'
    testImplementation 'mysql:mysql-connector-java:8.0.32'
    // Google sheets
    implementation 'com.google.api-client:google-api-client:2.2.0'
    implementation 'com.google.apis:google-api-services-sheets:v4-rev20230227-2.0.0'
    //s3
    implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.12.429'
    //thymeleaf
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    //testing
    testImplementation 'org.mockito:mockito-core:5.2.0'
}

我尝试降级到 SB 2.7,以防这是后来引入的更改,但这产生了一系列其他问题,所以我恢复了。

我已经检查过它正在运行 Hibernate ORM 核心版本 6.1.5.Final,它应该与 io.hypersistence:hypersistence-utils-hibernate-60:3.0.1 兼容。

我尝试删除一些注释(见上文)以了解特定注释是否会触发错误,但由于只有同时使用两个注释时,我不确定。

我尝试在 Slack 上找到类似的问题,但似乎没有一个是完全正确的。

如果有人知道如何解决错误,或者如果我错过了一些有关如何正确升级的文档,我将非常感谢您的支持。

最好的, 维克多

java spring-boot hibernate annotations
1个回答
0
投票

检查您的实体类是否有使用 @Type(type = "list_array") 之类的实例,并确保将其替换为 @JdbcTypeCode(SqlTypes.ARRAY)。我遇到了类似的问题,在进行这些更改后得到了解决。

© www.soinside.com 2019 - 2024. All rights reserved.