How to access a value defined in the application.properties file in Spring Boot

Qasim picture Qasim · May 29, 2015 · Viewed 438.6k times · Source

I want to access values provided in application.properties, e.g.:

logging.level.org.springframework.web: DEBUG
logging.level.org.hibernate: ERROR
logging.file=${HOME}/application.log

userBucket.path=${HOME}/bucket

I want to access userBucket.path in my main program in a Spring Boot application.

Answer

Master Slave picture Master Slave · May 29, 2015

You can use the @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.