在开发过程中,可能有多个不同环境的配置文件,例如:开发环境,测试环境,预发环境,生产环境等。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