簡體   English   中英

在運行時覆蓋`spring.cloud.config.profile`

[英]Override `spring.cloud.config.profile` at runtime

我正在使用Spring cloud config,我需要在運行時覆蓋我的spring.cloud.config.profile屬性為bluegreen

我有一個方法determineConfigProfile()返回bluegreen但是如何在獲取配置之前告訴Spring Boot運行該方法(即解析配置屬性),如何告訴Spring Boot覆蓋系統屬性?

我在這里看到https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_client.html那個"profile" = ${spring.profiles.active} (actually Environment.getActiveProfiles())但我沒有了解如何設置活動配置文件。

離開這個是因為我認為這很有用,我所做的是在我的public class Application extends SpringBootServletInitializer

我做了以下工作:

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        String profile = determineConfigProfile();
        System.setProperty("spring.cloud.config.profile", profile);
        return application.sources(Application.class);
    }

該操作在Spring雲配置啟動並覆蓋配置文件之前運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM