Hi,
I haven't trolled throught the forums about this topic (oh, fine, it takes all of a minute, I'll do that... NOW)
Ok, so I just had a quick glance and can't see this anywhere
When I use inheritance on my cool spring beans, as in, declare one as abstract and the other as a child of the abstract, the abstract bean isn't actually instantiated in any way.
Which is obvious.
But, let's say I have the following scenario:
The problem I'm finding is that the map defined in the abstract bean is completely thrown away by the child bean, and only the child bean's (in this case, child's) parameterValues map is preserved.Code:<bean id="parent" abstract="true"> //a plethora of properties <property name="parameterValues"> <map> <entry key="key1"> <value>key1</value> </entry> </map> </property> <bean id="child" parent="parent" class="my.domain.here.DataRequest"> // more properties <property name="parameterValues"> <map> <entry key="key2"> <value>key2</value> </entry> </map> </property> </bean>
I actually went to some lengths in the DataRequest class to ensure I could actually do the above:
This lets me keep on adding stuff to the parameterValues.Code:public void setParameterValues(Map<String, String> defaultParameters) { if (this.parameterValues == null) this.parameterValues = defaultParameters; else { if (defaultParameters == null) this.parameterValues = null; else { this.parameterValues.putAll(defaultParameters); } } }
So, to recap:
How I thought spring worked - I declare an abstract bean, it instantiates/does stuff in some way, and then I declare a child bean.
That child bean has all the properties of the parent AND the child.
How it looks like spring works - I declare an abstract bean, it does nothing. It's just xml. Then I declare a child bean, that child has all the non-conflicting -property-name values of the parent AND the child. If a property name conflict occurs, only the child bean's is used.
Is this so? And if so, why?
Cheers,
Andrew


Reply With Quote
