【问题标题】:Spring PropertyPlaceholderConfigurer and keys with multiple valuesSpring PropertyPlaceholderConfigurer 和具有多个值的键
【发布时间】:2013-12-17 23:21:50
【问题描述】:

我有一个这样的属性文件:

firstproperty=1,2,3,4
secondproperty=47,998,120
thirdproperty=54

我的属性文件在我的 Spring 配置中被很好地定义为我的 PropertyPlaceHolderConfigurer bean 的属性。

我想在

中加载值
HashMap<String, ArrayList<String>> 

像这样:

<util:map id="properties" map-class="java.util.HashMap">
    <entry key="first" value="${firstproperty}" />
    <entry key="second" value="${secondproperty}" />
    <entry key="three" value="${thirdproperty}" />
</util:map>

问题在于,对于每个条目,以逗号分隔的多个值都算作一个值。我试图将我的 util-map 的值类型配置为 ArrayList,但没有成功。有什么想法吗?

P.S : 我使用 Spring 3.2。

【问题讨论】:

  • 您可以访问此链接:stackoverflow.com/questions/12576156/…希望对您有所帮助。
  • @Freeman 谢谢,实际上我已经阅读了它,但我并不完全满意,因为我需要将我的 bean 注入管理到 Spring 配置文件中,而不是在 Java 代码中。

标签: java spring properties-file


【解决方案1】:

我在配置文件中搜索了 Spring EL,也许这就是你想要的:

<bean id="taxCalculator" class="org.spring.samples.TaxCalculator">
<property name="defaultLocale" value="#{ systemProperties['user.region'] }.split(',')"/>

<!-- other properties -->

我不确定拆分方法的位置,您可以自己尝试找到正确的方法。更多详情请参考:http://docs.spring.io/spring/docs/3.0.x/reference/expressions.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    相关资源
    最近更新 更多