如何访问Spring Boot中application.properties文件中定义的值

编程入门 行业动态 更新时间:2024-10-09 21:27:44
本文介绍了如何访问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文件中定义的值

本文发布于:2023-11-28 17:47:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643367.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:定义   文件   Boot   Spring   properties

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!