Profile是Spring用来针对不同环境对不同配置文件的支持,全局的配置使用application-{profile}.properties(如:application-dev.properties)。
通过在application.properties文件中设置spring.profiles.active=dev来指定活动的Profile。
下面我们来指定开发环境端口是8080,正式环境是80
- 生产环境和开发环境的配置如下:
application-prod.properties
server.port=80
application-dev.properties
server.port=8080
- 在application.properties文件中设置活动的Profile:
spring.profiles.active=dev