• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SpringWebMVC : Referencing a bean defined in WebApplicationContext2 from WebApplicationContext1

 
Ranch Hand
Posts: 52
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic