profile 可以让 Spring 对不同的环境提供不同配置的功能,可以通过激活、指定参数等方式快速切换环境。
换句话说,就是我们需要在不同的场景下使用不同的配置,profile的出现就是要解决我们多环境下切换配置复杂的问题。

Profile的基本使用

properties

  • applcation.properties:公共配置
  • application-dev.properties:开发环境配置
  • application-test.properties:测试环境配置
  • application-prod.properties:生产环境配置

激活指定配置

server.port=8081
spring.profiles.active=dev

#ymal:
server:
   port:8081
spring:
  profiles:
    active: dev
---
server:
  port:8083
spring:
  profiles: dev
---
server:
  port:8085
spring:
  profiles: prod