|
From: <jue...@we...> - 2004-11-10 12:51:36
|
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=3D"sessionFactory" =
class=3D"org.springframework.orm.hibernate.LocalSessionFactoryBean">
...
<property name=3D"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=3D"sessionFactory" =
class=3D"org.springframework.orm.hibernate.LocalSessionFactoryBean">
...
<property name=3D"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=3D"sessionFactory" =
class=3D"org.springframework.orm.hibernate.LocalSessionFactoryBean">
...
<property name=3D"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=E9sar Ordi=F1ana
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=20
module jar.
For example, if we have a module called module1, we have a=20
"module1-applicationContext.xml" which goes to a "spring" folder inside=20
the module1.jar. Then, if we want to use the module1 into one of our=20
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=20
modified by more than one module. One example is the=20
org.springframework.orm.hibernate.LocalSessionFactoryBean =20
mappingResources property. Each of our modules have their own hibernate=20
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=20
format to allow to modify already defined beans, instead of redefining=20
them, maybe something like:
module1-applicationContext.xml:
<bean id=3D"mySessionFactory" definition=3D"add">
<property name=3D"mappingResources">
<list>
<value>module1/Element.hbm.xml</value>
</list>
</property>
</bean>=20
module2-applicationContext.xml:
<bean id=3D"mySessionFactory" definition=3D"add">
<property name=3D"mappingResources">
<list>
<value>module2/Order.hbm.xml</value>
<value>module2/Line.hbm.xml</value>
</list>
</property>
</bean>=20
For now, we have solved the LocalSessionFactoryBean issue by extending=20
it and allowing the list of mapping resources to be added by other=20
beans. Also we have developed a simple BeanPostProcessor which allows us =
to put the hibernate mappings per module, and it adds them to the=20
extended LocalSessionFactoryBean automatically.
Anyway, we are looking also for a more general solution, like the one=20
stated by Rod. Our projects are based on portlets, and we would like to=20
extract common modules of each portlet webapp to be handled by a common=20
parent context. I still haven't tried the=20
ContextSingletonBeanFactoryLocator class.
Rod Johnson wrote:
> James
>
> I agree that this would be useful--especially for Geronimo, which you=20
> and I have discussed before. In fact it's something we could consider=20
> for 1.2, so I'd like to see a discussion here about what it should=20
> entail.
>
> I also agree with Mike re no enforcement of JNDI for cross-referencing =
> if at all possible.
>
> I would like a deployment unit to:
>
> - accommodate any config format, not just XML
> - allow a hierarchy of contexts in a single deployment unit
>
> Rgds
> Rod
>
> jas...@ma... wrote:
>
>> Its an interesting question. Just one immediate thought; I can see=20
>> there being a need for a Spring deployment unit of some kind; e.g. a=20
>> jar containing an applicationContext.xml file in APP-INF/ or=20
>> something - maybe having any additional jars required inside the jar=20
>> in APP-INF/lib.
>>
>> One there's a deployment unit we can add native support to Geronimo=20
>> (and other containers could support it too) plus we could support hot =
>> deployment of units inside Spring natively rather than relying on the =
>> J2EE deployment units (WAR / EAR / RAR)
>>
>> If there was a deployment unit; the only real issue is how to handle=20
>> cross-deployment unit references; but we could always use JNDI / JMX=20
>> for that or use a hierarchy of BeanFactory instances.
>>
>>
>> On 9 Nov 2004, at 22:51, James Cook wrote:
>>
>>> We have been developing a large enterprise application using Spring=20
>>> and it
>>> has proven to be a very effective framework. We use the Data access
>>> abstractions heavily, along with transaction management and =
Hibernate
>>> support.
>>>
>>> Now that we have most of the concepts down, some coworkers and=20
>>> myself are
>>> now considering the challenges inherent in packaging our business=20
>>> objects,
>>> service layers, spring configuration files, etc. into reusable=20
>>> component
>>> packages. We want to be able to give other developers in the company =
>>> a jar
>>> file that contains all of this content and simply drop it into their
>>> project.
>>>
>>> There are a lot of similarities (and differences) between what we=20
>>> face and
>>> what EJB components deal with. EJB has solutions for mapping=20
>>> dependencies in
>>> a component package to the primary application (ejb-ref, etc.) and=20
>>> we are
>>> beginning to talk about how to accomplish similar behavior using=20
>>> Spring.
>>>
>>> Ultimately, there are probably many nuances to this process that we=20
>>> won't
>>> know until we actual do it, but I was wondering if the development=20
>>> team has
>>> some insight into some of the Spring features that already exist=20
>>> that can
>>> assist in some of these challenges? Perhaps also there are some=20
>>> features
>>> that are on the drawing board to assist in this matter also?
>>
--=20
C=E8sar Ordi=F1ana
CTO, DiSiD SLL http://www.disid.com
Parc Tecnol=F2gic. Av. Benjamin Franklin, 12
Centre de Negocis Edifici CEEI
46980 Val=E8ncia - Espa=F1a
Tel +34 646 10 92 84
-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=3D5588&alloc_id=3D12065&op=3Dclick
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|