I have a scenario where I need to inject values to the Arraylist in a class that does not have the setter I believe in this scenario I need to do a get on the list in the POC class and then do a add:
public class POC {
private ArrayList<String> beheaviour=new ArrayList<String>();
public ArrayList<String> getBeheaviour() {
return beheaviour;
}
}
Here is the xml mapping code :
<bean id="poc" class="outBoundocument.factory.POC">
<property name="beheaviour">
<list>
<value>temp1</value>
<value>temp2</value>
<value>temp3</value>
<value>temp4</value>
<value>temp5</value>
</list>
</property>
</bean>
the following code returns :
Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property ‘beheaviour’ of bean class [outBoundocument.factory.POC]: Bean property ‘beheaviour’ is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
I have no control over the POC class as its a external vendor provided class and I cant do a constructor injection to it as the only way to add values to it is in the following way :
POC poc=new POC();
poc.getBeheaviour().add("some Stuff")
As far as I know, Spring will not be able to help you here (if you do not have access to the code). Spring only allows you to work with closed-source classes as beans if you define it in XML, which in turn makes it impossible to do attribute injection.
If you are not tied to Spring, you can do what you need with Java Reflection.
UPDATE
Apologies, it seems you can autowire via XML. Have a look here.