Aug 24th, 2007, 09:19 AM
Multiple web-app issue with one database module.
We have two web-app using common data access module. One webapp uses spring container and another not. But the second one needs access to database. Database DAO beans are in spring.
so, we created a ApplicationContextAware class with a static method getContext() which loads spring DAO beans. Now both works fine.
One requirement is like when one webapp do some changes in database the other one needs to be notified. Hibernate sure has event package, but, in our case the Hibernate SessionFactory is in different container.
so, we created a Hierarchical ApplicationContext and tried to access using beanRefContext.xml, but because of separate webapps, the container is loaded twice, once for each web app.
Now my question is "is there any way to publish the ApplicationContext by any mean so that any other modules getting started any time just lookup and get if available the ApplicationContext?"
Aug 24th, 2007, 09:24 AM
Register the ApplicationContext in JNDI and retrieve it from there. Search the forum there are a few samples/threads covering this issue.
Aug 24th, 2007, 02:50 PM
Something must be wrong in your setup because this is supposed to work. One reason might be that you have the Spring jar in one webapp, so it is loaded by the webapp's classloader instead of a shared one.
Originally Posted by whyagnesh23
Aug 27th, 2007, 12:42 AM
so i suppose to put spring.jar in db only?
Thanx for replay, i'm trying to do it by JNDI but still if it is possible that we can directly use available context in server then there is no need for jndi. let me try though....
So do i suppose to put my spring.jar in the database module only? But my web application also need spring container. and i'm just supplying database classes as jar to all other modules.
Aug 27th, 2007, 05:06 PM
Could you please say to which post you refer?
IMHO I don't see how Marten's answer on JNDI is related to your issue. Maybe he might comment. But I'd say don't get confused by JNDI, it won't help you.
Aug 28th, 2007, 01:33 AM
I referred both the posts in fact. And yes! i may have confused by JNDI, cause i was trying to register my app-context but won't find a way. Then i tried using spring JNDI provoder http://opensource.atlassian.com/proj...rowse/SPR-1422 . but still confused.
Originally Posted by Jörg Heinicke
Jörg, can u please help me to eloborat what i'm suppose to do in case of having single jar. i mean what am i suppose to do for all my modules using same jar. My requirement says all my modules needs to be that decoupled that each could be on different JVM or different machine.
what i understood from Marten's answer is whenever some other modules started it first search the applicationContext in some specific jndi and if it finds the entry then won't start new context and use the available one. but if it don't find the entry it'll start the new one and register in the jndi to be used by other modules.
while talking about jndi my concepts are little fuzzy but i'm just trying to have some registry which publish the state (already available or not) of app-context. hope that will help.
Thenx for redirection in advance..
Aug 28th, 2007, 09:15 AM
Have you read the article? The idea is about putting the common stuff on the common or shared class loader, so that it is available in all web applications. This means also the spring.jar. Without it the suggested approach does neither work since it depends on static variable in a particular class. All web applications can so share the same parent application context.