|
From: <co...@di...> - 2004-11-10 15:08:25
|
Thanks for the tip Juergen. I like very much the mappingJarLocations approach. Anyway, in case it could be needed for other beans, what do you think about the idea to allow to modify or extend a bean from one definition file, which is already defined in a previous definition file, instead of completely redefining them? jürgen höller [werk3AT] wrote: >One way to achieve automatic loading of all Hibernate mapping files would be to put them into the lib directory as separate files, alongside the module jar files, and refer to them as follows: > > <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"> > ... > <property name="mappingDirectoryLocations"> > <list> > <value>WEB-INF/lib</value> > </list> > </property> > </bean> > >You could also tell Hibernate to load all mapping files found in your module jars: > > <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"> > ... > <property name="mappingJarLocations"> > <list> > <value>WEB-INF/lib/module1.jar</value> > <value>WEB-INF/lib/module2.jar</value> > <value>WEB-INF/lib/module3.jar</value> > </list> > </property> > </bean> > >To make the latter option more convenient, I've just added a ResourceArrayPropertyEditor that can automatically resolve file patterns as Resource array. "mappingJarLocations" takes a Resource array, so you can specify a pattern there now (as direct value): > > <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"> > ... > <property name="mappingJarLocations"> > <list> > <value>WEB-INF/lib/module*.jar</value> > </list> > </property> > </bean> > >Juergen > > >-----Original Message----- >From: spr...@li... >[mailto:spr...@li...]On Behalf >Of César Ordiñana >Sent: Wednesday, November 10, 2004 12:36 PM >To: spr...@li... >Subject: Re: [Springframework-developer] Creating reusable component >packages with Spring > > >Hi all, > >We have just tried to solve the same challenge as James. We have found a >partial solution by putting the applicationContext.xml files into each >module jar. > >For example, if we have a module called module1, we have a >"module1-applicationContext.xml" which goes to a "spring" folder inside >the module1.jar. Then, if we want to use the module1 into one of our >webapps, we only have to add the jar into the WEB-INF/lib folder and add >its applicationContext.xml file to the config locations, like this: > > <context-param> > <param-name>contextConfigLocation</param-name> > <param-value> > classpath:spring/module1-applicationContext.xml > classpath:spring/module2-applicationContext.xml > classpath:spring/module3-applicationContext.xml > applicationContext.xml > </param-value> > </context-param> > >It works very well, except for those beans whose properties can be >modified by more than one module. One example is the >org.springframework.orm.hibernate.LocalSessionFactoryBean >mappingResources property. Each of our modules have their own hibernate >mappings, with relationships between modules, and all of them have to be >handled by the same SessionFactory. > >One way to handle it could be to extend the spring beans definition >format to allow to modify already defined beans, instead of redefining >them, maybe something like: > >module1-applicationContext.xml: > <bean id="mySessionFactory" definition="add"> > <property name="mappingResources"> > <list> > <value>module1/Element.hbm.xml</value> > </list> > </property> > </bean> > >module2-applicationContext.xml: > <bean id="mySessionFactory" definition="add"> > <property name="mappingResources"> > <list> > <value>module2/Order.hbm.xml</value> > <value>module2/Line.hbm.xml</value> > </list> > </property> > </bean> > >For now, we have solved the LocalSessionFactoryBean issue by extending >it and allowing the list of mapping resources to be added by other >beans. Also we have developed a simple BeanPostProcessor which allows us >to put the hibernate mappings per module, and it adds them to the >extended LocalSessionFactoryBean automatically. > >Anyway, we are looking also for a more general solution, like the one >stated by Rod. Our projects are based on portlets, and we would like to >extract common modules of each portlet webapp to be handled by a common >parent context. I still haven't tried the >ContextSingletonBeanFactoryLocator class. >Rod Johnson wrote: > > -- Cèsar Ordiñana Navarro CTO, DiSiD SLL http://www.disid.com Parc Tecnològic. Av. Benjamin Franklin, 12 Centre de Negocis Edifici CEEI 46980 València - España Tel +34 646 10 92 84 |