Configure active profile in SpringBoot via Maven

前端 未结 7 1585
执笔经年
执笔经年 2020-11-29 20:13

I\'m trying to set an active profile in Spring Boot application using Maven 3.
In my pom.xml I set default active profile and property spring.pr

7条回答
  •  佛祖请我去吃肉
    2020-11-29 21:03

    There are multiple ways to set profiles for your springboot application.

    1. You can add this in your property file:

      spring.profiles.active=dev
      
    2. Programmatic way:

      SpringApplication.setAdditionalProfiles("dev");
      
    3. Tests make it very easy to specify what profiles are active

      @ActiveProfiles("dev")
      
    4. In a Unix environment

      export spring_profiles_active=dev
      
    5. JVM System Parameter

      -Dspring.profiles.active=dev
      

    Example: Running a springboot jar file with profile.

    java -jar -Dspring.profiles.active=dev application.jar
    

提交回复
热议问题