Neo4j-harness 为 Scala.Serializable 抛出 java noclassdefound 异常
Neo4j-harness throws java noclassdeffound exception for Scala.Serializable
尝试使用 neo4j-harness 测试 Neo4j 服务器时,我在构建嵌入式 Neo4j 服务器时遇到 noclassdeffound
异常
private final Neo4j embeddedNeo4jServer = Neo4jBuilders.newInProcessBuilder()
.withDisabledServer()
.withFixture("")
.build(); // exception here
我的 pom.xml 看起来像这样:
<dependencies>
<!-- Core Dependencies -->
<dependency><groupId>org.neo4j.driver</groupId><artifactId>neo4j-java-driver</artifactId><version>4.4.5</version></dependency>
<dependency><groupId>org.apache.kafka</groupId><artifactId>kafka-streams</artifactId><version>3.0.0</version></dependency>
<dependency><groupId>org.apache.curator</groupId><artifactId>curator-x-discovery</artifactId><version>4.2.0</version></dependency>
<dependency><groupId>org.json</groupId><artifactId>json</artifactId><version>20211205</version></dependency>
<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-simple</artifactId><version>1.7.30</version></dependency>
<!-- Test Dependencies -->
<dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter</artifactId><version>5.8.2</version><scope>test</scope></dependency>
<dependency><groupId>org.skyscreamer</groupId><artifactId>jsonassert</artifactId><version>1.5.0</version><scope>test</scope></dependency>
<dependency><groupId>org.neo4j.test</groupId><artifactId>neo4j-harness</artifactId><version>4.4.5</version><scope>test</scope></dependency>
<!-- Spring dependencies for an embedded Kafka instance -->
<dependency><groupId>org.springframework.kafka</groupId><artifactId>spring-kafka</artifactId><version>2.8.3</version><scope>test</scope></dependency>
<dependency><groupId>org.springframework.kafka</groupId><artifactId>spring-kafka-test</artifactId><scope>test</scope><version>2.8.3</version></dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><version>2.6.4</version>
<exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency>
<!-- Mockito dependencies - NOTE: the inline dependency replaces the core one, but might be removed in future versions-->
<!--<dependency><groupId>org.mockito</groupId><artifactId>mockito-core</artifactId><version>4.4.0</version><scope>test</scope></dependency>-->
<dependency><groupId>org.mockito</groupId><artifactId>mockito-junit-jupiter</artifactId><version>4.4.0</version><scope>test</scope></dependency>
<dependency><groupId>org.mockito</groupId><artifactId>mockito-inline</artifactId><version>4.4.0</version><scope>test</scope></dependency>
</dependencies>
spring-kafka-test
和 neo4j-harness
中使用的 scala-library 版本存在冲突。
要解决此问题,您可以从 spring-kafka-test
中排除 scala 依赖项,这意味着 neo4j-harness
版本将用于两者。
为此,请在 pom.xml 中添加排除项:
<dependency><groupId>org.springframework.kafka</groupId><artifactId>spring-kafka-test</artifactId><scope>test</scope><version>2.8.3</version>
<exclusions><exclusion><groupId>org.scala-lang</groupId><artifactId>scala-library</artifactId></exclusion></exclusions></dependency>
尝试使用 neo4j-harness 测试 Neo4j 服务器时,我在构建嵌入式 Neo4j 服务器时遇到 noclassdeffound
异常
private final Neo4j embeddedNeo4jServer = Neo4jBuilders.newInProcessBuilder()
.withDisabledServer()
.withFixture("")
.build(); // exception here
我的 pom.xml 看起来像这样:
<dependencies>
<!-- Core Dependencies -->
<dependency><groupId>org.neo4j.driver</groupId><artifactId>neo4j-java-driver</artifactId><version>4.4.5</version></dependency>
<dependency><groupId>org.apache.kafka</groupId><artifactId>kafka-streams</artifactId><version>3.0.0</version></dependency>
<dependency><groupId>org.apache.curator</groupId><artifactId>curator-x-discovery</artifactId><version>4.2.0</version></dependency>
<dependency><groupId>org.json</groupId><artifactId>json</artifactId><version>20211205</version></dependency>
<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-simple</artifactId><version>1.7.30</version></dependency>
<!-- Test Dependencies -->
<dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter</artifactId><version>5.8.2</version><scope>test</scope></dependency>
<dependency><groupId>org.skyscreamer</groupId><artifactId>jsonassert</artifactId><version>1.5.0</version><scope>test</scope></dependency>
<dependency><groupId>org.neo4j.test</groupId><artifactId>neo4j-harness</artifactId><version>4.4.5</version><scope>test</scope></dependency>
<!-- Spring dependencies for an embedded Kafka instance -->
<dependency><groupId>org.springframework.kafka</groupId><artifactId>spring-kafka</artifactId><version>2.8.3</version><scope>test</scope></dependency>
<dependency><groupId>org.springframework.kafka</groupId><artifactId>spring-kafka-test</artifactId><scope>test</scope><version>2.8.3</version></dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><version>2.6.4</version>
<exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency>
<!-- Mockito dependencies - NOTE: the inline dependency replaces the core one, but might be removed in future versions-->
<!--<dependency><groupId>org.mockito</groupId><artifactId>mockito-core</artifactId><version>4.4.0</version><scope>test</scope></dependency>-->
<dependency><groupId>org.mockito</groupId><artifactId>mockito-junit-jupiter</artifactId><version>4.4.0</version><scope>test</scope></dependency>
<dependency><groupId>org.mockito</groupId><artifactId>mockito-inline</artifactId><version>4.4.0</version><scope>test</scope></dependency>
</dependencies>
spring-kafka-test
和 neo4j-harness
中使用的 scala-library 版本存在冲突。
要解决此问题,您可以从 spring-kafka-test
中排除 scala 依赖项,这意味着 neo4j-harness
版本将用于两者。
为此,请在 pom.xml 中添加排除项:
<dependency><groupId>org.springframework.kafka</groupId><artifactId>spring-kafka-test</artifactId><scope>test</scope><version>2.8.3</version>
<exclusions><exclusion><groupId>org.scala-lang</groupId><artifactId>scala-library</artifactId></exclusion></exclusions></dependency>