The main issue I was trying to resolve was coupling. We are working on a very large spring/hibernate project with several decoupled subsystems. These subsystems each have their own application context, but share the same hibernate session factory. Because of this we had one shared file and bean definition for our hibernate session factory definition. Developers were frequently adding and removing hibernate mapping file definitions each time this shared hibernate session factory needed a change. This shared file proved too fast moving for such a large group, so we managed to move each list of hibernate mappings to their own individual project's application context. We then referenced these mapping definitions from one bean definition.
Code:
<bean id="hibernateMappingLocations"
class="com.mycompany.spring.CombineListFactoryBean">
<property name="lists">
<list>
<ref bean="service1.hibernateMappings"/>
<ref bean="service2.hibernateMappings"/>
<ref bean="service3.hibernateMappings"/>
<ref bean="service4.hibernateMappings"/>
<ref local="service5.hibernateMappings"/>
<ref bean="service6.hibernateMappings"/>
</list>
</property>
</bean>
This moved us in the right direction since now this shared mapping definition rarely needed to change. This still was not perfect, however, since we wanted to easily be able to deploy service1 in isolation from other services. Using the definition above, we would need to manually comment out the other services to accomplish this since spring rightfully would complain it is missing bean definitions. What we really wanted was to reference all list beans defined with the "<service>.hibernateMappings" naming convention.
Code:
<bean id="hibernateMappingLocations"
class="com.mycompany.spring.CombineListFactoryBean">
<property name="lists">
<!-- Reference all lists beans with id's ending with .hibernateMappings -->
<bean
class="com.mycompany.spring.RegExpRefFactoryBean">
<property name="patterns">
<list>
<value>(.*)\.hibernateMappings</value>
</list>
</property>
<property name="type">
<value>java.util.List</value>
</property>
</bean>
</property>
</bean>
Now if we deploy service1 without the other services, spring will not complain we are missing bean definitions. As long as each service follows the naming convention <service>.hibernateMappings, their hibernate mapping files will be included in the session factory definition.
Sorry for the long explanation.
Thanks.
-karl