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;
    }
发布了155 篇原创文章 · 获赞 11 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/u013919153/article/details/104895070