Setting the default active profile in Spring-boot

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

    We to faced similar issue while setting spring.profiles.active in java.

    This is what we figured out in the end, after trying four different ways of providing spring.profiles.active.

    In java-8

    $ java --spring.profiles.active=dev -jar my-service.jar
    Gives unrecognized --spring.profiles.active option.
    
    $ java -jar my-service.jar --spring.profiles.active=dev
    # This works fine
    
    $ java -Dspring.profiles.active=dev -jar my-service.jar
    # This works fine
    
    $ java -jar my-service.jar -Dspring.profiles.active=dev
    # This doesn't works
    

    In java-11

    $ java --spring.profiles.active=dev -jar my-service.jar
    Gives unrecognized --spring.profiles.active option.
    
    $ java -jar my-service.jar --spring.profiles.active=dev
    # This doesn't works
    
    $ java -Dspring.profiles.active=dev -jar my-service.jar
    # This works fine
    
    $ java -jar my-service.jar -Dspring.profiles.active=dev
    # This doesn't works
    

    NOTE: If you're specifying spring.profiles.active in your application.properties file then make sure you provide spring.config.location or spring.config.additional-location option to java accordingly as mentioned above.

提交回复
热议问题