Spring Boot使用多个环境的配置文件

在开发过程中,可能有多个不同环境的配置文件,例如:开发环境,测试环境,预发环境,生产环境等。Spring Boot支持程序启动时在配置文件 application.yml 中指定环境的配置文件,配置文件格式为application-{porfile}.properties,其中{profile}对应环境的标识,例如:

  • application-test.properties——测试环境;

  • application-dev.properties——开发环境;

  • application-uat.properties——预发环境;

  • application-prod.properties——生产环境;

如何指定这个环境的配置文件呢?只需要在application.yml中加上 spring.profiles.active的配置,该配置指定采用哪一个profiles。例如使用application-dev.properties,则配置代码如下:

spring:
  profiles:
    active: dev
发布了3 篇原创文章 · 获赞 0 · 访问量 20

猜你喜欢

转载自blog.csdn.net/weixin_42466157/article/details/104414866