如何访问Spring Boot中application.properties文件中定义的值 [英] How to access a value defined in the application.properties file in Spring Boot
本文介绍了如何访问Spring Boot中application.properties文件中定义的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想访问 application.properties
中提供的值,例如:
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
我想访问 userBucket.path
在Spring Boot应用程序的主程序中。
I want to access userBucket.path
in my main program in a Spring Boot application.
推荐答案
你可以使用 @Value
注释并在您正在使用的任何一个Spring bean中访问该属性
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.
这篇关于如何访问Spring Boot中application.properties文件中定义的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文