Kafka 测试容器未运行
Posted
技术标签:
【中文标题】Kafka 测试容器未运行【英文标题】:Kafka testcontainer not running 【发布时间】:2020-12-27 16:51:20 【问题描述】:我正在尝试为 debezium 集成设置一个集成测试环境(按照example 中的说明进行操作),但测试容器(默认图像:confluentinc/cp-kafka:5.2.1)没有启动,但会抛出一个例外。
我正在使用下面提到的代码来创建一个 KafkaContainer bean
@Bean
public KafkaContainer kafkaContainer()
if (kafkaContainer == null)
kafkaContainer = new KafkaContainer()
.withNetwork(network())
.withExternalZookeeper("172.17.0.2:2181");
kafkaContainer.start();
return kafkaContainer;
它抛出以下异常。
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.testcontainers.containers.KafkaContainer.getBootstrapServers(KafkaContainer.java:91)
The following method did not exist:
org/testcontainers/containers/KafkaContainer.getHost()Ljava/lang/String;
The method's class, org.testcontainers.containers.KafkaContainer, is available from the following locations:
jar:file:/home/shubham/.m2/repository/org/testcontainers/kafka/1.14.3/kafka-1.14.3.jar!/org/testcontainers/containers/KafkaContainer.class
The class hierarchy was loaded from the following locations:
org.testcontainers.containers.KafkaContainer: file:/home/shubham/.m2/repository/org/testcontainers/kafka/1.14.3/kafka-1.14.3.jar
org.testcontainers.containers.GenericContainer: file:/home/shubham/.m2/repository/org/testcontainers/testcontainers/1.12.5/testcontainers-1.12.5.jar
org.testcontainers.containers.FailureDetectingExternalResource: file:/home/shubham/.m2/repository/org/testcontainers/testcontainers/1.12.5/testcontainers-1.12.5.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.testcontainers.containers.KafkaContainer
2020-09-10 01:09:49.937 ERROR 72507 --- [ main] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener
【问题讨论】:
更多细节,好吗?什么样的异常?另外,即使你发布了一个链接,最好添加一个代码sn-p @VitalyChura 我添加了代码 sn-ps 和 strack 跟踪日志。 【参考方案1】:在 maven 依赖项中使用了旧版本的 org.testcontainers,它可以工作。谢谢!
【讨论】:
我打算建议尝试一个更新的,但是好的,不管用什么)以上是关于Kafka 测试容器未运行的主要内容,如果未能解决你的问题,请参考以下文章
避免Kafka客户端无法连接Docker上运行的Kafka,又名:Docker如何添加hosts映射
从 Docker 容器将 PySpark 连接到 Kafka