对于最新的稳定版本,请使用 Spring Cloud Kubernetes 3.3.0spring-doc.cadn.net.cn

Kubernetes PropertySource 实现

配置 Spring Boot 应用程序的最常见方法是创建一个application.propertiesapplication.yaml或 一application-profile.propertiesapplication-profile.yaml文件,其中包含键值对,这些键值对为您的 应用程序或 Spring Boot Starters。您可以通过指定系统属性或环境来覆盖这些属性 变量。spring-doc.cadn.net.cn

要启用此功能,您需要将spring.config.import应用程序配置属性设置为kubernetes:(使用 yaml 时用引号转义,例如。"kubernetes:"). 目前,您无法指定要加载的 ConfigMap 或 Secretspring.config.import,默认情况下 Spring Cloud Kubernetes 将根据spring.application.name财产。如果spring.application.name未设置,它将 加载名称为application.spring-doc.cadn.net.cn

如果您想加载 KubernetesPropertySources 在引导阶段,就像它在 3.0.x 版本之前一样 您可以添加spring-cloud-starter-bootstrap到应用程序的类路径或集合spring.cloud.bootstrap.enabled=true作为环境变量。spring-doc.cadn.net.cn

不支持在 Bootstrap 期间加载属性(使用spring-cloud-starter-bootstrapspring.cloud.bootstrap.enabled=true和荷载属性spring.config.import.您必须使用一种或另一种方法。