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

Spring Boot Kafka本地禁用SSL Bundle:配置置空及自动配置排除问题咨询

解决方案

一、本地开发禁用Kafka SSL

方法1:直接指定Kafka安全协议为PLAINTEXT(推荐)

不管全局SSL Bundle配置如何,只要将Kafka的安全协议设为PLAINTEXT,就会强制使用明文连接,无需复杂修改SSL Bundle配置。在application-local.yaml中添加:

spring:
  kafka:
    properties:
      security.protocol: PLAINTEXT
    ssl:
      bundle: null  # YAML中`null`为原生空值,Spring会识别并忽略全局SSL Bundle配置

方法2:清空SSL Bundle关联配置

如果一定要通过清空SSL Bundle实现禁用,可在本地配置中覆盖全局Bundle的子配置,并置空Kafka的SSL Bundle引用:

spring:
  ssl:
    bundle:
      jks:
        # 替换为你实际使用的Bundle名称,清空所有子配置
        my-kafka-bundle:
          key-store: null
          trust-store: null
  kafka:
    ssl:
      bundle: null

二、追加自动配置排除项(避免覆盖原有配置)

Spring Boot默认会用本地配置的spring.autoconfigure.exclude覆盖全局配置,要实现追加,可采用以下两种方式:

方法1:数组索引追加

在application-local.yaml中通过索引指定追加的排除类,假设全局application.yaml已有1个排除项,本地追加第二个时:

spring:
  autoconfigure:
    exclude[1]: org.springframework.boot.autoconfigure.security.servlet.SslAutoConfiguration

注意:索引从0开始,需对应全局配置的数组长度,不确定长度时推荐用方法2。

方法2:编程式追加排除项

创建本地环境专用配置类,通过代码追加排除项,不会覆盖全局配置:

import org.springframework.boot.autoconfigure.AutoConfigureExcludeFilter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(name = "spring.profiles.active", havingValue = "local")
public class LocalAutoConfigExclude {

    @Bean
    public AutoConfigureExcludeFilter autoConfigureExcludeFilter() {
        return new AutoConfigureExcludeFilter(
            org.springframework.boot.autoconfigure.security.servlet.SslAutoConfiguration.class
        );
    }
}

内容的提问来源于stack exchange,提问作者Shakirov Ramil

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 12:50:02