Insert a beans map using Spring from a properties file

I am trying to control which beans populate a map from a properties file using Spring 3. I find this question similar to How to populate a map configured with spring from a properties file , except in my case, my properties file has the names beans:

key1=bean1 key2=bean2 

I tried xml like:

 <bean id="bean1" class="java.lang.String"> <constructor-arg value="habeas corpus"/> </bean> <bean id="bean2" class="java.lang.String"> <constructor-arg value="platanos verdes"/> </bean> <bean id="map" class="java.util.HashMap"> <constructor-arg ref="props"/> </bean> <util:properties id="props" location="classpath:test.properties" /> 

But then the map is {key1: "bean1", key2: "bean2"} , whereas I want {key1: "habeas corpus", key2: "platanos verdes"} .

I disagree with this approach, so any other ideas on how I can control which beans fill the map will be great.

+1
source share

Source: https://habr.com/ru/post/988656/


All Articles