我有file.properties
这样:
parameterkey=one
parameterval=oneVal
parameterkey=two
parameterval=twoVal
parameterkey=three
parameterval=threeVal
如何将属性bean设置为wire parameterkey string list和parameterval string list?
现在我有了这个,但它只连接了相应变量中的最后一个参数和值:
<context:property-placeholder location="${env}.properties"/>
.....
<spring:bean id="myBean" class="mygroup.MyClass">
<spring:property name="queryParamKey">
<spring:list value-type="java.lang.String">
<spring:value>${parameterkey}</spring:value>
</spring:list>
</spring:property>
<spring:property name="queryParamVal">
<spring:list value-type="java.lang.String">
<spring:value>${parameterval}</spring:value>
</spring:list>
</spring:property>
</spring:bean>
答案 0 :(得分:2)
如果你在属性中有这个
app.myType[0].key=key1
app.myType[0].value=val1
app.myType[1].key=key2
app.myType[1].value=val2
你可以拥有@ConfigurationProperties:
@ConfigurationProperties(prefix="app")
@Component
public class PropertiesConfiguration {
private List<MyType> myType;
public static class MyType {
private String key;
private String value;
//getters setters
}
//getters setters
}
有关详细信息,请参阅here。