Comment ajouter plus de HBM aux MappingResources existants ou à la liste HBM existante au printemps

StackOverflow https://stackoverflow.com/questions/8973167

Question

J'ai un parent-app, qui comprend des sous-applications. Mon application parent a sa propre liste incluse de 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>

Mes sous-applications veulent ajouter sa propre liste de HBM dépendants aux parents. La façon dont cela devrait fonctionner est, si elle inclut cette sous-application, elle inclurait également le nouveau HBMS et l'enfant-apparierait l'inclusion.

Les nouveaux HBM à inclure pourraient ressembler à

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

Comment pouvons-nous le faire?

Était-ce utile?

La solution

Votre solution pourrait être:

Diviser les «mappingResources» pour

<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>

Dans l'enfant, référez-vous au bean "hbmsourcelist" et invoque un "addall" avec une autre liste via "MethoardInvokFactoryBean"

<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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top