View Full Version : making services accessible from multiple webapps
Aug 28th, 2004, 06:58 AM
I'm totally new to Spring and interested in using it in our GridSphere portal www.gridsphere.org which is JSR 168 compliant.
One of the issues we've had to deal with is how best to allow multiple webapps access to common services. Our solution has been to put many libraries in the "shared/lib" or "common/lib" directory of Tomcat so that all webapps have access to them. In addition it keeps each webapp from becoming heavily bloated with a lot of duplicate jars.. for instance we use Hibernate and this itself requires a mountain of jar files.
In looking at Spring it seems like every webapp has its own applicationContext.xml and so sharing services between webapps is not possible. Or is there a way to create some kind of "special-services.jar" that includes within a applicationContext.xml and hence all webapps can access it?
I would appreciate any comments especially on the pros and cons of putting libs in a shared classpath-- it seems most sites recommend sticking all jars in the webapps context classpath, but this seems like a lot of duplication and needless tracking of jars to me...
Aug 28th, 2004, 09:29 AM
Are the webapps related, as part of a J2EE application (EAR file in archive form), or are they basically loose webapps?
If they are not part of a J2EE application, then I don't think you really have much choice other than doing something like you mentioned. Loose webapps are supposed to be essentially isolated, sharing only J2EE authentication sessions, and nothing else really.
Of course, if you are willing to deploy the webapps as a combined J2EE application, then you have a lot more mechanisms to share things, with most appservers supporting hierarchical and unified classloader setups for the j2ee app...
Aug 28th, 2004, 03:35 PM
Would it be possible to share a Application Context via JNDI? If so, you could create a webapp that loads first, put the AppContext into JNDI. Then, as other webapps come online, each could find the global app context in JNDI.
We are going to have this exact requirement soon. There's no sense in giving each webapp its own copy of each service. We're running in Tomcat, so a EAR file isn't an option.
Aug 29th, 2004, 11:03 AM
Looks like I'm also in your situation, since I don't ahve a J2ee (ear). In fact the idea of a portlet container is to be able to handle any thrid party portlet webapp packaged as a WAR file.
I was thinking I could keep my current "PortletServiceFactory" and core services in shared space-- and then use that as a wrapper to access services Spring style--
How could I configure this PortletServicefactory (or any Spring service) for that matter as a JNDI resource. Especially if it doesn't require tweaking server.xml of Tomcat-- I would like to package it as part of my webapp context descriptor if possible...
Aug 29th, 2004, 04:08 PM
Not really sure... I'm sure you can manually put Spring services into JNDI. There might an automatic way to get the application context to place certain services into JNDI for you. There is a way to get a service from JNDI for injection. Question is, what's the best way to get service into JNDI? I haven't looked into it yet. You can always do it manually. :)
Aug 30th, 2004, 08:11 AM
One other thing to consider when trying to share objects via JNDI is that you may have classloader issues. If you have a hierarchical classloader setup, and one child tries to put something in JNDI, which includes classes loaded by a classloader on its branch, and then another child (on another branch of the tree) tries to access that object, it will probably fail since the same classes will be considered different by the VM for that child, as that child will be accessing them with its own classloader. For the sharing to work, all the classes have to be loaded by a classloader which is a parent to all the children classloaders.
Aug 30th, 2004, 11:02 AM
I just did exactly what you want. You want an applicationContext-services.xml in your services jar and then just specify that xml file in each webapp's web.xml:
My database datasource and hibernate config is in domain, all my services and transactional managers in common and UI stuff in portal. Each project's unit tests can reuse the exact same xml.
Aug 30th, 2004, 01:12 PM
That's a good way to split the app up. It would be nice, however, to not have to share the services jar at all. If we could somehow load the services into JNDI scope at boot time, all webapps could then share the services.
As Colin has mentioned, though, there may be class loader issues.
Worth exploring some more, though,
Nov 13th, 2005, 02:23 PM
I have the samre requirment and was wondering if anyone has found a solution?
I have multiple webapps and I would like them each to share common services.
Feb 16th, 2006, 03:52 PM
I'm wondering if anyone has figured out this issue as I now have multiple webapps that require the use of the same services/biz logic.
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.