|
From: <jue...@we...> - 2004-11-10 12:23:06
|
I see three levels of packaging here: 1. What you can already do is specify a config location like = "classpath*:META-INF/beans.xml", which will load all beans.xml files = from META-INF directories in all jar files found. Note that those will = get loaded into the *same* context, though, i.e. into a single = namespace. This is just a special way of loading bean definition files: = The jar files are plain and simple, no custom class loaders involved, no = special detection going on other than looking for certain resources in = the existing class loader (for example, a web application's class = loader). And this can be handled within an application (for example a = WAR file): It does not need special support by the server. 2. For EJB-style deployment with naming references, things become = harder. It might be appropriate to offer hooks for JNDI exposure here: A = server like Geronimo could detect special jar files (maybe through the = file extension), loading a local Spring application context for each jar = and exposing certain facade beans from there in JNDI. The actual JNDI = names could be specified at deployment time, like with EJB, putting the = onus of namespace management on the deployer. Spring bean names are just = used internally for the local context of each jar file; they do not = share a common namespace. A web application can then have its own Spring = root context with its own namespace, linking in the modules as JNDI = objects. This should still be possible with plain jars, in principle, = containing special descriptor files in the META-INF directory. 3. If additional libraries (that just apply to a specific module) can be = contained in the deployment unit, we're crossing into different = territory again. Essentially, this means having a separate class loader = per deployment unit. We're beyond a plain jar file and simple namespace = management here, coming close to an EJB jar or even an EAR file. This = means we're also incurring the risk of issues like conflicts between = different library versions etc, and the deployment hassle of respecting = the different class loaders involved. Option 1 is rather trivial, as it is essentially just a different flavor = of loading bean definition files in an application - in all other = respects, it's still typical Spring usage (in the current sense), for = example using the existing class loader of a WAR. This will seamlessly = work in any server. If the namespace problem arises, option 2 becomes interesting: = Individual jar files could then get deployed with special deployment = descriptors (inside or outside the jar), mapping local bean names in the = jar to global JNDI names - usually for facades of the module in that = jar. This would already need special support by the server, though, but = could still work as part of a WAR file. The web application could simply = expect specific facades at specific JNDI names; the deployer is = responsible for deploying the module jars accordingly. Option 3 is essentially the equivalent of local stateless session bean = deployment, requiring the modules to run in a different class loader = than the WAR file. It seems to me that this is not typically needed in = Spring scenarios: It might be sufficient to resort to local EJB = deployment in such a case, with a Spring context backing the stateless = sessions beans involved (through Spring's existing EJB support classes). = Of course, it might still be worthwhile to offer such a full-blown = deployment unit for plain Spring too. If not requiring module-specific = library deployment, option 2 is available as a simpler alternative. An interesting question is whether a variation of option 2 could be = provided without JNDI: i.e. auto-loading one context per jar file, with = the root application context directly linking in specific facades from = there. However, how would one identify a specific facade in a specific = jar file? In option 2 as outlined above, the deployer would do this for = each jar file - for example, through including a special descriptor in = the jar, mapping local bean names to global JNDI names. For option 2 without JNDI, we'd need to have unique bean definition file = names in the jar files, which can be clearly identified via the class = loader. In that case, the root context could load the jar-specific = contexts as beans, allowing to expose specific facades in those contexts = as beans in the root context. Each jar-specific context would still have = its own namespace; just specific beans would get linked into the root = context under appropriate names. There would be no further relationship = between the root context and the jar-specific contexts. A remaining problem for option 2 is how to make specific beans from the = root context visible to jar-specific contexts - linking in beans the = other way round. I don't think that it is generally appropriate to load = the jar-specific contexts as children of the root context; they should = rather be considered as independent. In the case of a JDBC DataSource, = one could resort to a shared JNDI location. But in the case of a = Hibernate SessionFactory, there should be a way to make a local instance = defined in the root context available to jar-specific contexts - with = the option to link it in under a specific bean name. Thoughts? Opinions? Juergen -----Original Message----- From: spr...@li... [mailto:spr...@li...]On Behalf Of jas...@ma... Sent: Wednesday, November 10, 2004 9:43 AM To: spr...@li... Subject: Re: [Springframework-developer] Creating reusable component packages with Spring 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 something=20 - maybe having any additional jars required inside the jar in=20 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=20 deployment of units inside Spring natively rather than relying on the=20 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 myself=20 > 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 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 we=20 > 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 that=20 > 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? > > > > ------------------------------------------------------- > 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_idU88&alloc_id=12065&op=3Dclick > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer > > James ------- http://radio.weblogs.com/0112098/ ------------------------------------------------------- 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_idU88&alloc_id=12065&op=3Dick _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer |
|
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
|
|
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 |
|
From: Patrick B. <pbu...@gm...> - 2004-11-10 15:37:24
|
On Wed, 10 Nov 2004 16:07:45 +0100, C=E9sar Ordi=F1ana <co...@di...> w= rote: > 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? I see an advantage of this since the project I'm working also needs the ability to essentially add to the definition of a bean. Our use-case is the same with respect to adding mappings to a Hibernate Session Factory. We have our core code and mappings in a jar file that gets used by many web apps. Each of these web apps should then be able to define their own mappings that possibly relate to the core ones, but add additional app specific entities. We have more than one SessionFactory since separate parts of the app can be stored in separate, unrelated databases. With the current setup, if the web app author wants to add a new mapping, they have to duplicate our SessionFactory definition, which would make future upgrades problematic since the end user would need to keep in sync with our latest SessionFactory definitions. I'm +1 for some mechanism to tell the bean factory to add to the current bean if already defined. Patrick |