Setting the default active profile in Spring-boot

前端 未结 14 1923
感动是毒
感动是毒 2020-12-13 08:20

I want my default active profile to be production if -Dspring.profiles.active is not set.

I tried the following in my application.pro

14条回答
  •  长情又很酷
    2020-12-13 09:13

    First of all, with the solution below, is necessary to understand that always the spring boot will read the application.properties file. So the other's profile files only will complement and replace the properties defined before.

    Considering the follow files:

    application.properties
    application-qa.properties
    application-prod.properties
    

    1) Very important. The application.properties, and just this file, must have the follow line:

    spring.profiles.active=@spring.profiles.active@
    

    2) Change what you want in the QA and PROD configuration files to see the difference between the environments.

    3) By command line, start the spring boot app with any of this options:

    It will start the app with the default application.properties file:

    mvn spring-boot:run
    

    It will load the default application.properties file and after the application-qa.properties file, replacing and/or complementing the default configuration:

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

    The same here but with the production environment instead of QA:

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

提交回复
热议问题