Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 按顺序加载spring中的属性文件_Java_Xml_Spring - Fatal编程技术网

Java 按顺序加载spring中的属性文件

Java 按顺序加载spring中的属性文件,java,xml,spring,Java,Xml,Spring,有没有办法在spring中按顺序加载属性文件?我知道属性是一个哈希表,映射是无序的。我想要基于xml的解决方案,而不是基于java的解决方案。理想情况下,这应该可以从外部进行配置 Edit: I mean the contents of the properties file should be read and preserved in the same order as in the properties file. Eg: fr.wiki=http://fr.wikipedia.org e

有没有办法在spring中按顺序加载属性文件?我知道属性是一个哈希表,映射是无序的。我想要基于xml的解决方案,而不是基于java的解决方案。理想情况下,这应该可以从外部进行配置

Edit: I mean the contents of the properties file should be read and preserved in the same order as in the properties file. Eg: fr.wiki=http://fr.wikipedia.org en.wiki=http://en.wikipedia.org ... If I read the properties file, fr.wiki should be first, en.wiki should be second and so on. 编辑: 我的意思是属性文件的内容应该按照与属性文件相同的顺序读取和保存。如: fr.wiki=http://fr.wikipedia.org 维基=http://en.wikipedia.org ... 如果我阅读属性文件,fr.wiki应该是第一个,en.wiki应该是第二个,依此类推。
无法按属性文件中写入属性的顺序获取属性。您可以在属性名称中添加数字:

component.01.key = value1
component.02.key = value2
component.03.key = value3
...

请参见使用
PropertyPlaceHolder

RU
?如果是,请检查您的用例是什么?为什么需要有序属性?我举了一个例子。让我们假设最后你有*.wiki=。我正在使用国际化。第一部分可能是一个基本正则表达式。我不希望一个更广泛的正则表达式在一个特定的正则表达式之前匹配。非常糟糕的解决方案。需要对内部代码进行更改,使其更难阅读、推理和维护。这是使用
java.util.Properties
所能获得的最好结果。您只需迭代
getPropertyNames()
,提取具有定义前缀的属性,然后对它们进行排序以获得您的有序值。那么,您真的认为,如果必须按键排序,我会问这个问题吗?属性文件中的所有行不能采用component.numeric格式,其中许多行包含数字字符和点。此外,组件名称是一个“变量”。组件名称本身可能需要排序。这给解析逻辑增加了很多复杂性,类似于创建一种新的文件格式,没有人可能会使用这种格式。我想如果你有
key1=val1
你可以在它前面加上类似
foo.01.key1=val1
的前缀,这样你就可以在键上使用字母数字排序了。我没有提出新的文件格式。您可能对您的解决方案感到满意,但我不是。