how to use Spring Boot profiles

前端 未结 12 1226
忘了有多久
忘了有多久 2020-12-04 21:14

i have application.yml,application-dev.ymlandapplication-dev.yml

  1. I\'m using the maven command mvn spring-boot:run
12条回答
  •  余生分开走
    2020-12-04 22:05

    Create specific .yml files in the resources directory for each and every environment(Eg: dev,qa,stg etc.) that you need to run the application. image of .yml files in resources directory

    If you are using spring-boot-maven-plugin 2.0.5.RELEASE in your pom.xml file you can add the profiles within the dependency tag as follows. image of pom.xml spring-boot-maven-plugin (you can configure multiple profiles using multiple profile tags)

    Then you can use the following commands to build and run the project.

    1) mvn clean install
    2) mvn spring-boot:run -Dspring-boot.run.default==qa
    

    Then you will see that the default profile is set as qa while running the project. displaying the default profile when running the application

提交回复
热议问题