本文介绍了如何访问Spring Boot中application.properties文件中定义的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想访问 application.properties 中提供的值,例如:
I want to access values provided in application.properties, e.g.:
logging.level.springframework.web: DEBUG logging.level.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文件中定义的值
发布评论