Friday, October 2, 2015

Spring Framework- 6 - InnerBeans

We could include innerbeans as shown in the code below:

<beans>
<bean id="triangle" class="com.findgoose.springDemo.Triangle">
<property name="pointA" ref="Bean-pointA">
<bean id="Bean-pointA" class="com.project.springDemo.Point">
<property name="x" value="10"/>
<property name="y" value="100"/>
</bean>
</property>
<property name="pointB" ref="Bean-pointB"/>
<property name="pointC" ref="Bean-pointC"/>
</bean>

<bean id="Bean-pointB" class="com.project.springDemo.Point">
<property name="x" value="20"/>
<property name="y" value="200"/>
</bean>
<bean id="Bean-pointC" class="com.project.springDemo.Point">
<property name="x" value="30"/>
<property name="y" value="300"/>
</bean>
</beans>

In the above code,

  • the ref tag and the id="Bean-pointA" tag is no more required.
  • pointA object can be embedded within the property tag of the "triangle" bean, in situations where it would be referred for instantiations only by the "triangle" bean. Which is why the above mentioned tags are no more needed either.

No comments:

Post a Comment