循环遍历文件中的所有属性,使用 spring 和 java [英] Looping through all the properties in a file, with spring and java
本文介绍了循环遍历文件中的所有属性,使用 spring 和 java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通常,当我知道属性名称时,我会使用注释填充字段:
Normally i would populate a field using annotations when I knew the property name like so :
@Value("${myproperties.myValue}")
private String myString
但是我现在想遍历文件中的所有属性,当它们的名称未知时,并存储那里的值和名称.spring 和 java 的最佳方式是什么?
However I now want to loop through all the properties in a file, when their names are unknown, and store both there value and name. What's the best way with spring and java ?
推荐答案
其实如果你只需要从文件中读取属性,而不是在 Spring 的属性占位符中使用这些属性,那么解决方案很简单
Actually if you need only to read properties from a file and not to use these properties in Spring's property placeholders, then the solution is simple
public class Test1 {
@Autowired
Properties props;
public void printProps() {
for(Entry<Object, Object> e : props.entrySet()) {
System.out.println(e);
}
}
...
<util:properties id="props" location="/spring.properties" />
这篇关于循环遍历文件中的所有属性,使用 spring 和 java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文