Home > Blockchain >  Read a Map from properties file through applicationContext.xml in spring
Read a Map from properties file through applicationContext.xml in spring

Time:10-24

I have a map in my properties file as below:

property1=Hello_1
property2=Hello_2
list={a:'A', b:'B', c:'C'}

and I have a model object that contains:

public class Model {

    String s1;
    String s2;
    Map<String, String> map;
}

and I want to read it from applicationContext.xml and fill it in my java Map like below:

<bean id="model" >
    <property name="s1" value="${property1}" />
    <property name="s2" value="${property2}" />
    <property name="map" value="${list}" />
</bean>

I can read s1 and s2 successfully and fill it in the model, but I don't know how to fill the map collection, any idea?

CodePudding user response:

You need to use Spring expression to handle that. Try <property name="map" value="#{${list}}" />

  • Related