• Post Reply Bookmark Topic Watch Topic
  • New Topic

SpringWebMVC : Referencing a bean defined in WebApplicationContext2 from WebApplicationContext1

 
Abhineet Kapil
Ranch Hand
Posts: 52
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abhineet Kapil
Ranch Hand
Posts: 52
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, your understanding sounds correct. If you need beans visible to both servlet contexts they should be defined in beans.xml.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!