3

I have a property file as such

com.country.<COUNTRY>=<values comma seperated>

For example:

com.country.UK=100,200
com.country.US=10,20

Now in future there can be many others country entries added Can I get these values in to a Map<String,List<Integer>> in spring application context xml via propertyPlaceHolder?

arghtype
  • 4,376
  • 11
  • 45
  • 60
JMJ
  • 85
  • 2
  • 10

1 Answers1

1

You can use spring util: Don't forget to import scheme, use util:map and util:list to construct any structure you want. It's ok to use ref-ids as values:

<beans  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="http://www.springframework.org/schema/util 
        http://www.springframework.org/schema/util/spring-util-2.5.xsd">

<util:map id="map1" map-class="java.util.HashMap">
    <entry key="smthgkey" value="smthvalue"/>
</util:map>

<util:list id="list1" list-class="java.util.ArrayList">
    <value>val1</value>
</util:list>

Alternative way is to create bean with necessary structure, but I never used this way. You can find examples here: How to define a List bean in Spring?

Community
  • 1
  • 1
arghtype
  • 4,376
  • 11
  • 45
  • 60
  • but how to get my dynamic property name and values mapped? – JMJ Oct 09 '13 at 16:05
  • once properties were loaded, the only way I know to reload them is to [refresh](http://docs.spring.io/spring/docs/3.0.5.RELEASE/api/org/springframework/context/support/AbstractApplicationContext.html#refresh%28%29) context. Maybe it is better to create custom method for reloading your properties directly from file (or db) without redundant context manipulations. – arghtype Oct 10 '13 at 08:42