Kubernetes PropertySource 实现

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

要启用此功能,你需要设置spring.config.import应用配置属性Kubernetes:(使用 yaml 时用引号转义,例如“库伯内特斯:”). 目前你无法指定一个配置文件地图或密钥来加载spring.config.import默认情况下,Spring Cloud Kubernetes会加载基于spring.application.name财产。 如果spring.application.name它没有设置加载一个带有名称的配置文件地图和/或秘密应用.spring-doc.cadn.net.cn

如果你想加载Kubernetes,那就要地产来源在引导阶段,就像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. 你必须采用其中一种方法。