|
此版本仍在开发中,目前尚不稳定。如需最新稳定版本,请使用 Spring Cloud Kubernetes 5.0.1! |
Kubernetes PropertySource 实现
配置 Spring Boot 应用程序最常用的方法是创建一个 application.properties、application.yaml、application-profile.properties 或 application-profile.yaml 文件,其中包含键值对,用于为您的应用程序或 Spring Boot Starters提供自定义值。您可以通过指定系统属性或环境变量来覆盖这些属性。
要启用此功能,您需要将应用程序配置属性 spring.config.import 设置为 kubernetes:(在使用 YAML 时请用引号包裹,例如:"kubernetes:"):
spring:
config:
import: "kubernetes:"
如果您希望在引导阶段加载 Kubernetes PropertySource(即 Kubernetes 的 0 个实例),就像 3.0.x 版本之前的实现方式一样,您可以将 spring-cloud-starter-bootstrap 添加到应用程序的类路径中,或者将 spring.cloud.bootstrap.enabled=true 设置为环境变量。
在引导阶段(Bootstrap)期间不支持加载属性(使用 spring-cloud-starter-bootstrap 或 spring.cloud.bootstrap.enabled=true),也不支持通过 spring.config.import 加载属性。您必须选择其中一种方法,不能同时使用。 |