当尝试使用@EmbeddedKafka
from时,我在运行测试时spring-kafka-test
最终得到ClassNotFoundException: scala.collection.convert.AsJavaExtensions
(full stack trace here )。
我尝试了不同的 Kafka 版本(org.apache.kafka:kafka_2.11:2.4.1
而不是org.apache.kafka:kafka_2.12:2.8.0
)以及不同的版本org.scala-lang:scala-library
(2.13.6
,,,,2.12.10
)。2.11.12
2.10.6
为了解决这个问题,我需要做什么?
以下是重现该问题的最小示例:
src/main/kotlin/com/acme/Application.kt
package com.acme
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
@SpringBootApplication
class Application
fun main(args: Array<String>) {
runApplication<Application>(*args)
}
src/test/kotlin/com/acme/integration/TestFullStack.kt
package com.acme.integration
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.kafka.test.context.EmbeddedKafka
import org.springframework.test.context.junit.jupiter.SpringExtension
@ExtendWith(SpringExtension::class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EmbeddedKafka(topics = ["testtopic"], controlledShutdown = true)
class TestFullStack {
@Test
fun `test init`() {
}
}
build.gradle.kts
plugins {
id("org.springframework.boot") version "2.5.4"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.5.21"
kotlin("plugin.spring") version "1.5.21"
}
group = "com.acme"
version = "1.0.0-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
dependencies {
implementation(group = "org.apache.kafka", name = "kafka_2.12", version = "2.8.0")
implementation(group = "org.scala-lang", name = "scala-library", version = "2.12.10")
implementation(group = "org.springframework.kafka", name = "spring-kafka", version = "2.7.6")
implementation(group = "org.springframework.boot", name = "spring-boot-starter-web")
implementation(group = "org.jetbrains.kotlin", name = "kotlin-reflect")
testImplementation(group = "org.springframework.boot", name = "spring-boot-starter-test")
testImplementation(group = "org.springframework.kafka", name = "spring-kafka-test", version = "2.7.6")
testImplementation(group = "org.testcontainers", name = "kafka", version = "1.16.0")
testImplementation(group = "org.jetbrains.kotlin", name = "kotlin-test-junit")
}
tasks {
withType<Test> {
testLogging.exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
useJUnitPlatform()
}
}
settings.gradle.kts
rootProject.name = "acmetest"
Dockerfile
FROM openjdk:11-jdk-slim
WORKDIR /home/test
ADD . /home/test
RUN ./gradlew test