首页 > 解决方案 > 为什么 ${spring.embedded.kafka.brokers} 没有填充到 application-test.yaml 虽然我看到 spring.embedded.kafka.brokers 存在?

问题描述

我们正在使用@EmbeddedKafka,并且application-test.yml我们有

kafka:
  confluentBootstrapAddress: ${spring.embedded.kafka.brokers}

我可以看到那confluentBootstrapAddressnull

但是,如果在调试模式下,我会检查这个

this.resolveEmbeddedValue("${spring.embedded.kafka.brokers}") = "127.0.0.1:51020"

然后我可以看到该值存在,并且嵌入式 Kafka 确实已启动。

可能是什么问题?application.yml评估时刻与嵌入式代理启动时的生命周期/时刻不匹配?

标签: javaspringapache-kafkaspring-kafkaspring-kafka-test

解决方案


实际上,在使用@Profile而不是@ActiveProfiles. 将其更改为ActiveProfiles使 Spring Test 考虑到"spring-profile.properties".


推荐阅读