Setting the default active profile in Spring-boot

前端 未结 14 1749
感动是毒
感动是毒 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:16

    Currently using Maven + Spring Boot. Our solution was the following:

    application.properties

    #spring.profiles.active= # comment_out or remove
    

    securityConfig.java

    @Value(${spring.profiles.active:[default_profile_name]}")
    private String ACTIVE_PROFILE_NAME;
    

    Credit starts with MartinMlima. Similar answer provided here:

    How do you get current active/default Environment profile programmatically in Spring?

    0 讨论(0)
  • 2020-12-13 09:16

    you can also have multiple listings in the @Profile annotation

    @Profile({"dev","default"})
    

    If you set "default" as an additional value, you don't have to specify spring.profiles.active

    0 讨论(0)
提交回复
热议问题