在依赖检查警告的驱动下,我们尝试使用 spring-kafka:2.2.7 在我们的设置中将 org.apache.kafka:kafka-clients 的版本提升到 2.2.1 版本。
因此,使用 EmbeddedKafkaRule 的测试在代理启动期间失败,并出现 IOException 声称“无法加载 /some/path..”
java.io.IOException: Failed to load /Users/[..]/target/embedded-kafka during broker startup
at kafka.log.LogManager$$anonfun$createAndValidateLogDirs$1.apply(LogManager.scala:152)
at kafka.log.LogManager$$anonfun$createAndValidateLogDirs$1.apply(LogManager.scala:149)
at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
at kafka.log.LogManager.createAndValidateLogDirs(LogManager.scala:149)
at kafka.log.LogManager.<init>(LogManager.scala:80)
at kafka.log.LogManager$.apply(LogManager.scala:953)
at kafka.server.KafkaServer.startup(KafkaServer.scala:237)
at kafka.utils.TestUtils$.createServer(TestUtils.scala:132)
at kafka.utils.TestUtils.createServer(TestUtils.scala)
at org.springframework.kafka.test.EmbeddedKafkaBroker.afterPropertiesSet(EmbeddedKafkaBroker.java:223)
at org.springframework.kafka.test.rule.EmbeddedKafkaRule.before(EmbeddedKafkaRule.java:109)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
我们确保类路径上没有冲突的 kafka-clients 版本,并且还尝试将 EmbeddedKafkaRule 的 logs.dir 指定到 maven 目标文件夹下的某个文件夹,如上例中的“target/embedded-kafka”。两者都没有成功。
有人遇到同样的问题并解决了吗?