• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

SpringWebMVC : Referencing a bean defined in WebApplicationContext2 from WebApplicationContext1

 
Ranch Hand
Posts: 52
Eclipse IDE Spring Java
  • 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.

 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • 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 Spring Java
  • 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 Mac OS X IntelliJ IDE Spring Linux
  • 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.
 
The only thing that kept the leeches off of me was this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic