spring - Does the parent attribute of bean tag is equivalent to inheritance in Java? -


i started studying spring documentation. came across parent attribute explanation, using parent attribute between 2 beans equivalent inheritance relationship between these classes?

if so, how perform method overriding? saw in context, use of both parent attribute in xml config file , extends keyword in bean class. required specify both springs in order implement inheritance?

  • in spring, parent in bean configuration signifies configuration inheritance , not related java inheritance.
  • the configuration inheritance saves lot of code away repeated xml code.

for example, have following bean attributes

class mybean {     attrib1     attrib2     attrib3     attrib4 }  

say 1 instance of bean bean1 needs attrib1 , attrib2 whereas bean2 instance needs 4 attributes.

lets configure these 2 beans

<bean id="bean1" class="mybean">     <property name="attrib1" value="val1" />     <property name="attrib2" value="val2" /> </bean>  <bean id="bean2" parent="bean1">     <property name="attrib3" value="val3" />     <property name="attrib4" value="val4" /> </bean> 

note bean2 needed configure attrib3 , attrib4. other 2 attributes inherited bean1

to answer question:

does required specify both springs in order implement inheritance?

no. mentioned earlier not same java inheritance.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -