springboot 之 多環境配置

開發測試過程中,往往配置信息和正式版本的信息不同,爲了避免多次修改配置文件,我們可以使用spring的多環境配置。

方法有多種,這裏介紹我一般使用的方法。

將通用信息寫到application.properties文件中,將不同配置信息分別寫到不同的配置文件中。

測試結果:

#多環境指定配置
#生產
spring.profiles.active=dev
#測試
#spring.profiles.active=test

結果顯示:

dev configuration
#多環境指定配置
#生產
#spring.profiles.active=dev
#測試
spring.profiles.active=test

結果顯示:

test configuration

測試函數:

    @Value("${test_content}")
    private String test_content;

    @GetMapping(value = "api/v4/test_content")
    public String hello4(){
        return test_content;
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章