Setting active profile and config location from command line in spring boot

后端 未结 11 1626
借酒劲吻你
借酒劲吻你 2020-11-27 09:33

I have a spring boot application.

I have three profiles in my application-> development, staging and production. So I have 3 files

  1. ap
11条回答
  •  心在旅途
    2020-11-27 10:32

    We want to automatically pick property file based upon mentioned the profile name in spring.profiles.active and the path in -Dspring.config.location

    application-dev.properties
    

    If we are running jar in Unix OS then we have to use / at the end of -Dspring.config.location otherwise it will give below error.

    Error :: java.lang.IllegalStateException: File extension of config file location 'file:/home/xyz/projectName/cfg' is not known to any PropertySourceLoader. If the location is meant to reference a directory, it must end in '/'

    Example

    java -Dspring.profiles.active=dev -Dspring.config.location=/home/xyz/projectName/cfg/ -jar /home/xyz/project/abc.jar
    

    or

    java -jar /home/xyz/project/abc.jar --spring.profiles.active=dev --spring.config.location=/home/xyz/projectName/cfg/
    

提交回复
热议问题