You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kafka Stream项目application.yml中spring重复键问题求助

解决YAML中重复spring键的配置问题

错误根源很直接:YAML语法不允许同一层级出现重复的键,你当前配置里写了两个顶级的spring:节点,所以解析器抛出了重复键错误。

只需要把第二个spring:下的mvc配置块,合并到第一个spring:节点下,和cloud保持同级即可,完全不会破坏原有Kafka相关配置。正确的配置如下:

spring:
  cloud:
    function:
      definition: consumer;producer
    stream:
      kafka:
        bindings:
          producer-out-0:
            producer:
              configuration:
                value.serializer: <packagename>

          consumer-in-0:
            consumer:
              configuration:
                value.deserializer: <packagename>
        binder:
          brokers: localhost:9092   
      bindings:
        producer-out-0:
          destination: <topic name>
          producer:
            useNativeEncoding: true # Enables using the custom serializer
        consumer-in-0:
          destination: <topic name>
          consumer:
            use-native-decoding: true # Enables using the custom deserializer 
  # 将mvc配置移至此处,与cloud同级
  mvc:
    pathmatch:
      matching-strategy: ANT_PATH_MATCHER   

注意:YAML对缩进极度敏感,要确保mvc的缩进和cloud完全一致(都是spring:下的二级节点),避免因缩进错误导致配置层级混乱。

内容的提问来源于stack exchange,提问作者Sumeeth Kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 02:15:42