Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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
                Can you give a little more detail? What have you tried? If you've tried something, and failed, what was the error?
– spencergibb
                Apr 21, 2016 at 8:06
                I have tried using @PropertyResource and he ignored the external location and started on tomcat default port
– Amir Botvinik Nadiv
                Apr 21, 2016 at 8:09

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.

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, 2016 at 8:44 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, 2016 at 11:27 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, 2016 at 13:16 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, 2016 at 14:34

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"
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.