yaml 文件中的 KafkaListener 多个主题

KafkaListener mulitple topics in yaml file

我想阅读多个主题,所以我在 yaml 文件中用逗号分隔声明了它们,但出现以下错误:

java.lang.IllegalStateException: 主题 [topic-1, topic-2, topic-3, topic-4, topic-5, topic-6, topic-7] is/are 不是present 和 missingTopicsFatal 为 true

Spring:
  kafka:
    topics:
      tp: topic-1 ,  topic-2,  topic-3,  topic-4,  topic-5,  topic-6, topic-7
@KafkaListener(topics = "#{'${spring.kafka.topics.tp}'.split(',')}",
        concurrency = "190",
        clientIdPrefix = "client1",
        groupId = "group1")
public void listenData(final ConsumerRecord<Object, Object> inputEvent) throws Exception {
    handleMessage(inputEvent);
}

if i declare all topics inside KafkaListener annotation its working fine.

删除空格

tp: topic-1,topic-2,topic-3,topic-4,topic-5,topic-6,topic-7

或使用

.split(' *, *')