I am learning spring boot config externalization. I would like my application to read configuration from any external file (/Users/<userid>/application.properties).
I created spring-web project, and added spring.config.location=${user.home} entry to src/main/resource/application.properties
testConfig is the configuration property name I am trying to access via below code in my Controller class.
@Value("${testConfig}) private String configValue; I have given different values for testConfig in different places.
testConfig=InsideJar in src/main/resources/application.properties file. testConfig=ApplicationRoot in project root directory application.properties file.
testConfig=homeDir in user home directory /User/<userid>/application.properties file.
How I ran the app and what is the result?
1. From different directory than project root Command:
java -jar ../Downloads/first-springboot-app/target/first-springboot-app-0.0.1-SNAPSHOT.jar -Dspring.config.location=file:/User/${LOGNAME}/application.propertiesResult:InsideJarExpected result :homeDir
.
2. From Project root directory Command:
java -jar target/first-springboot-app-0.0.1-SNAPSHOT.jar -Dspring.config.location=file:/Users/${LOGNAME}/application.propertiesResult:
applicationRootDirExpected result :homeDir
3. Added spring.config.name=application 4. Added spring.config.name=application.properties Both of the above (3,4) gave same result .
Result:applicationRootDirExpected result :homeDir.
I already went through below links and other blogs .
Springboot doc
SO, SO.
Question/Problem : Why value (homeDir) is not fetched from Users/<userid>/application.properties ?
Any help would highly appreciated.
homeDiras the result rather than other results.in project root directorywhich issrc ? 2) where are passing the value for this${LOGNAME}` placeholder ? @new_programmersrcfolder. 2. ${LOGNAME} is to replace with userID. so that the path form to/User/<userId>(which is the directory where myapplication.propertiesreside)