Kubernetes PropertySource 实现
配置 Spring Boot 应用程序最常见的方法是创建 application.properties 或 application.yaml 文件,或 application-profile.properties 或 application-profile.yaml 文件,其中包含为应用程序或 Spring Boot 启动器提供自定义值的键值对。您可以通过指定系统属性或环境变量来覆盖这些属性。
要启用此功能,您需要将 spring.config.import 应用程序配置属性设置为 kubernetes:(在使用 yaml 时用引号转义,例如 "kubernetes:")。目前您不能使用 spring.config.import 指定要加载的 ConfigMap 或 Secret,默认情况下,Spring Cloud Kubernetes 将根据 spring.application.name 属性加载 ConfigMap 和/或 Secret。如果未设置 spring.application.name,它将加载名为 application 的 ConfigMap 和/或 Secret。
如果您希望在引导阶段加载 Kubernetes PropertySource,就像 3.0.x 版本之前那样,您可以将 spring-cloud-starter-bootstrap 添加到应用程序的类路径中,或者将 spring.cloud.bootstrap.enabled=true 设置为环境变量。
不支持在引导阶段(使用 spring-cloud-starter-bootstrap 或 spring.cloud.bootstrap.enabled=true)加载属性,同时又使用 spring.config.import 加载属性。您必须使用其中一种方法。 |