Kubernetes PropertySource 實作

配置 Spring Boot 應用程式最常見的方法是建立 application.propertiesapplication.yaml,或是 application-profile.propertiesapplication-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 設定為環境變數。