Setting active profile and config location from command line in spring boot

后端 未结 11 1589
借酒劲吻你
借酒劲吻你 2020-11-27 09:33

I have a spring boot application.

I have three profiles in my application-> development, staging and production. So I have 3 files

  1. ap
11条回答
  •  孤城傲影
    2020-11-27 10:29

    My best practice is to define this as a VM "-D" argument. Please note the differences between spring boot 1.x and 2.x.

    The profiles to enable can be specified on the command line:

    Spring-Boot 2.x (works only with maven)

    -Dspring-boot.run.profiles=local
    

    Spring-Boot 1.x

    -Dspring.profiles.active=local
    

    example usage with maven:

    Spring-Boot 2.x

    mvn spring-boot:run -Dspring-boot.run.profiles=local
    

    Spring-Boot 1.x and 2.x

    mvn spring-boot:run -Dspring.profiles.active=local
    

    Make sure to separate them with a comma for multiple profiles:

    mvn spring-boot:run -Dspring.profiles.active=local,foo,bar
    
    mvn spring-boot:run -Dspring-boot.run.profiles=local,foo,bar
    

提交回复
热议问题