添加jsonschema2pojo-core后嵌入式Kafka测试用例报错

问题描述

我有一个使用 Spring boot 和 Spring kafka 库创建的应用程序。现在我将 jsonschema2pojo-core 库添加到我的 pom 文件中。添加此 jar 文件后,我的测试用例失败并出现以下错误

Caused by: org.springframework.beans.factory.BeanCreationException: Error create bean with name 'embeddedKafka': Invocation of init method failed;嵌套异常是 java.lang.NoClassDefFoundError: scala/runtime/java8/JFunction0$mcZ$sp 引起:java.lang.NoClassDefFoundError:scala/runtime/java8/JFunction0$mcZ$sp

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.1.RELEASE</version>
    <relativePath />
</parent>

    <dependency>
        <groupId>org.springframework.kafka</groupId>
        <artifactId>spring-kafka</artifactId>
    </dependency>
    <!-- Test Dependencies -->
    <dependency>
        <groupId>org.springframework.kafka</groupId>
        <artifactId>spring-kafka-test</artifactId>
        <scope>test</scope>
    </dependency>

      <dependency>
        <groupId>org.jsonschema2pojo</groupId>
        <artifactId>jsonschema2pojo-core</artifactId>
        <version>1.0.2</version>
      </dependency>

解决方法

大概类似于这个https://docs.spring.io/spring-kafka/docs/2.5.11.RELEASE/reference/html/#jacksonscala-incompatibility

该库引入了不兼容的 Scala 库。

是的,添加

<dependency>
    <groupId>org.scala-lang</groupId>
    <artifactId>scala-library</artifactId>
    <version>2.12.11</version>
</dependency>

为我修好了;但我不能保证 jsonschema2pojo 将适用于该版本。

scala 人员因在补丁版本中破坏 API 更改而臭名昭著。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...