在Spring Boot中通过动态键读取属性 [英] Read properties by dynamic keys in spring boot
本文介绍了在Spring Boot中通过动态键读取属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道在Spring Boot中是否可以使用动态键从属性文件中读取属性值.我知道属性可以放在application.properties
中,并且可以使用@Value("propertyKey")
读取,但是我的键将是动态的.
I wanted to know if there is any way in Spring Boot to read property values from properties file by using Dynamic Keys. I know properties can be put in application.properties
and can be read using @Value("propertyKey")
But my keys are going to be dynamic.
我了解@PropertySource
可以读取属性值,并且可以动态构造键.那么Spring Boot提供了什么方法?
I know about @PropertySource
to read property values and I can construct my keys dynamically. So is there any way that is provided by Spring Boot?
推荐答案
您可以使用:
@Autowired
private Environment env;
,然后从代码中加载属性:
and then load property from code:
env.getProperty("your.property")
这篇关于在Spring Boot中通过动态键读取属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文