snippetjavaspringCritical
How to access a value defined in the application.properties file in Spring Boot
Viewed 0 times
howaccesspropertiesthespringdefinedfilevalueapplicationboot
Problem
How can I access values provided in
For instance, I want to access
application.properties, likelogging.level.org.springframework.web: DEBUG
logging.level.org.hibernate: ERROR
logging.file=${HOME}/application.log
userBucket.path=${HOME}/bucketFor instance, I want to access
userBucket.path in my main program in a Spring Boot application.Solution
You can use the
The Externalized Configuration section of the Spring Boot docs, explains all the details that you might need.
@Value annotation and access the property in whichever Spring bean you're using@Value("${userBucket.path}")
private String userBucketPath;The Externalized Configuration section of the Spring Boot docs, explains all the details that you might need.
Code Snippets
@Value("${userBucket.path}")
private String userBucketPath;Context
Stack Overflow Q#30528255, score: 848
Revisions (0)
No revisions yet.