Reputation: 10274
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.
Upvotes: 9
Views: 1370
Reputation: 33151
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.
Upvotes: 2
Reputation: 2685
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
Upvotes: 2
Reputation: 231
Well, it seems in your case you dont need environment variable. For production server your property file will be staying in and in staging machine it is also staying at same place. So where ever you deploy it will pick from . IMO you don't need to set environment, you just have to point property file to Now to define this path you have 2 ways.. - You can put static path in your code - You can set environment variable like Property_Path and read it in spring boot application..
However If you want to go one step ahead, you can use spring cloud configuration manager, by passing application+profile name to it, CM can fetch property file from directly from git or file system for you ...
Upvotes: 0