7

I am trying to put bootstrap.properties from outside my jar, so it won't get overridden by other developers by mistake. Could you please advice here?

This is its' content - directing to the spring server config

# application name
spring.application.name=elixium
# The server entry point
spring.cloud.config.uri=http://localhost:8888
pramodc84
  • 1,576
  • 2
  • 25
  • 33

2 Answers2

17

Spring Cloud uses the the same locations as spring boot to find bootstrap.properties (or .yml). So classpath:,classpath:/config,file:,file:config/ is the default search path, ./config/ is the highest precedence. If your file is in ./config or ./ it should just work. The property (spring.cloud.bootstrap.location) to change the location is slightly different than boot.

spencergibb
  • 24,471
  • 6
  • 69
  • 75
  • Thanks Spencer , yes I would like to change it's location . So should I use spring.cloud.bootstrap.location inside bootstrap.properties ? – Amir Botvinik Nadiv Apr 21 '16 at 08:44
  • 3
    No, it needs to be a env var, cmd line arg or java system property, otherwise you get a chicken and egg problem. How can you read the location of `bootstrap.properties` if you don't know the location ahead of time. – spencergibb Apr 21 '16 at 11:27
  • Well It can reach bootstrap.properties but I want to direct it outside my jar – Amir Botvinik Nadiv Apr 21 '16 at 11:34
  • I have tried to use as enviorment parameters spring.cloud.bootstrap.location=C:\test\test.. This did not work and i have tried to do the same as cmd line param. Maybe can you link me to an example for this 2 approaches? I have tried to change location but it is not clear how. Tnx – Amir Botvinik Nadiv Apr 21 '16 at 13:16
  • 1
    Thank you Spencer - I have solved it with environment variable : spring.cloud.bootstrap.location C:\tradair\config\tang\bootstrap.properties – Amir Botvinik Nadiv Apr 21 '16 at 14:34
  • AND also updated to 1.04 version : org.springframework.cloud spring-cloud-config-client 1.0.4.RELEASE – Amir Botvinik Nadiv Apr 21 '16 at 14:43
  • I solved it by adding --spring.cloud.bootstrap.location={{app_dir}}/bootstrap.properties in service file while starting application – Amit Sadafule Aug 08 '19 at 07:56
2

spring.cloud.bootstrap.location behaves like spring.config.location (in Spring Boot 2), it replaces the location of these configuration files.

To make it working, it has to defined as a system property.
For example :

With Jar :

java -jar
     -Dspring.cloud.bootstrap.location=anyLocation/bootstrap.yml 
      ...

With Spring Boot maven plugin :

mvn spring-boot:run 
   -Dspring-boot.run.jvmArguments="-Dspring.cloud.bootstrap.location=anyLocation/bootstrap.yml"
davidxxx
  • 125,838
  • 23
  • 214
  • 215