aspose file tools*
The moose likes Spring and the fly likes SpringWebMVC : Referencing a bean defined in WebApplicationContext2 from WebApplicationContext1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "SpringWebMVC : Referencing a bean defined in WebApplicationContext2 from WebApplicationContext1" Watch "SpringWebMVC : Referencing a bean defined in WebApplicationContext2 from WebApplicationContext1" New topic
Author

SpringWebMVC : Referencing a bean defined in WebApplicationContext2 from WebApplicationContext1

Abhineet Kapil
Ranch Hand

Joined: Feb 08, 2010
Posts: 52

Hi,

I have defined two WebApplicationContexts(i.e. Dispatcher Servlets) in my SpringWebMVC app with different url-patterns.
Each dispatcher servlet has its own config file defining beans in it.

Now I make a web request for the first dispatcher servlet. The targeted handler defined in first WebApplicationContext is invoked.
In that handler, Can I programatically get a reference to the bean defined in the other WebApplicationContext ?

I have tried using WebApplicationContextUtils, RequestContextUtils helpers and also ApplicationContextAware interface.
In all above cases, I always get the currently active WebApplicationContext.

Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

That would defeat the purpose of a WebApplicationContext. Beans defined in there should be visible to that servlet only. Beans that should be shared across web contexts should be defined in the root context. Do you have a root context? If you need more assistance with this please post your web.xml.


[How To Ask Questions][Read before you PM me]
Abhineet Kapil
Ranch Hand

Joined: Feb 08, 2010
Posts: 52

Yes, I have defined a root context as well.
And I understand that all the beans defined in the root context are shared across all the WebApplicationContexts.

But was just wondering if there was a possibility to peek into another WebAppContext. Thanks for Confirming !!




Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

Yes, your understanding sounds correct. If you need beans visible to both servlet contexts they should be defined in beans.xml.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SpringWebMVC : Referencing a bean defined in WebApplicationContext2 from WebApplicationContext1