How do I activate a Spring Boot profile when running from IntelliJ?

前端 未结 13 1559
醉梦人生
醉梦人生 2021-01-30 00:09

I have 5 environments:

 - local (my development machine)
 - dev
 - qc
 - uat
 - live
 - staging

I want different application properties to be u

13条回答
  •  爱一瞬间的悲伤
    2021-01-30 00:22

    I ended up adding the following to my build.gradle:

    bootRun {
      environment SPRING_PROFILES_ACTIVE: environment.SPRING_PROFILES_ACTIVE ?: "local"
    }
    
    test {
      environment SPRING_PROFILES_ACTIVE: environment.SPRING_PROFILES_ACTIVE ?: "test"
    }
    

    So now when running bootRun from IntelliJ, it defaults to the "local" profile.

    On our other environments, we will simply set the 'SPRING_PROFILES_ACTIVE' environment variable in Tomcat.

    I got this from a comment found here: https://github.com/spring-projects/spring-boot/pull/592

提交回复
热议问题