Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment specific properties from user home in springboot

I am working on a spring boot application in which i have to set Environment specific properties from user home folder.

i dig Google for the same & found we can put different properties file (dev, test, production) under resources and then we have to tell spring boot which environment we want to use using spring.profiles.active=dev OR prod.

however, my requirement is quite different. i will put a file in user home in my system & want to read properties form that file. how can i do that, need guidance.

Helping hands will be highly appreciated.

like image 423
Pankaj Arora Avatar asked Dec 07 '16 18:12

Pankaj Arora


2 Answers

From the Spring Boot docs:

You can also refer to an explicit location using the spring.config.location environment property (comma-separated list of directory locations, or file paths).

As the docs go on to state, this must be specified on the command line or as an environment variable.

$ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
like image 170
Jamie Bisotti Avatar answered Oct 16 '22 17:10

Jamie Bisotti


We explain that use case in a Devoxx presentation using EnvironmentPostProcessor, please refer to this section of the presentation for more details. You can also find the code sample online.

like image 2
Stephane Nicoll Avatar answered Oct 16 '22 17:10

Stephane Nicoll