I have a list of integers like 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
I want to use it as an integer array in my POJO.
However, I do not want it inside my class, but want to externalize it into the properties file and then inject it in my xml as a property of the class.
How to do it ?
Thanks for reading!
Seperating the values with comma should do it
if your class looks something like this
Class MyCLass
{
private Integer[] myIntArray;
public Integer[] getMyIntArray(){
return this.myIntArray;
}
public void setMyIntArray(Integer[] intArray){
this.myIntArray=intArray;
}
}
Your context file should have something like this:
<bean id="myBean" class="MyClass">
<property name="myIntArray" value="1,2,3,4,5"></property>
</bean>
if you want to user a properties file:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:myProps.properties"/>
</bean>
<bean id="myBean" class="MyClass">
<property name="myIntArray" value="${myvalues}"></property>
</bean>
In you myProps.properties file
myvalues=1,2,3,4,5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With