How to add more hbm to existing mappingResources or existing hbm list in Spring

796 views Asked by At

I have a parent-app, which includes sub-apps. My Parent app has its own included list of hbms

   <bean name="mappingResources"
      class="my.xxx.MyListFactoryBean">
        <property name="sourceList">
            <list>
                <value>aaa/bbb/aa.hbm.xml</value>
                <value>aaa/bbb/bb.hbm.xml</value>
                <value>aaa/bbb/cc.hbm.xml</value>
            </list>
      </property>
    </bean>

My sub-apps want to add its own list of dependent hbms to the parent-app's. The way it should work is, if it includes this sub-app then it would include the new hbms as well and the child-app would initiate the include.

new hbms to be included could look like

xx/dd.hbm.xml xx/ee.hbm.xml

How can we do it?

1

There are 1 answers

0
TorjeC On BEST ANSWER

Your Solution could be:

Split up the 'mappingResources' to

<bean name="mappingResources" class="my.xxx.MyListFactoryBean">
    <property name="sourceList" ref="hbmSourceList" />
</bean>

<bean id="hbmSourceList" class="java.util.ArrayList">
    <constructor-arg>
        <list>
            <value>aaa/bbb/aa.hbm.xml</value>
            <value>aaa/bbb/bb.hbm.xml</value>
            <value>aaa/bbb/cc.hbm.xml</value>
        </list>
    </constructor-arg>
</bean>

In the child-app refer to the bean "hbmSourceList" and invoke an "addAll" on it with an another list via the "MethodInvokingFactoryBean"

<bean id="hbmSourceListExtender" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject"><ref bean="hbmSourceList"/></property>
    <property name="targetMethod"><value>addAll</value></property>
    <property name="arguments">
        <ref local="childAppHbmSourceList"/>
    </property>
</bean>

<bean id="childAppHbmSourceList" class="java.util.ArrayList">
    <constructor-arg>
        <list>
            <value>xx/dd.hbm.xml</value>
            <value>xx/ee.hbm.xml</value>
        </list>
    </constructor-arg>
</bean>