Announcement Announcement Module
Collapse
No announcement yet.
Accessing the Application Context from a servlet Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing the Application Context from a servlet

    I'm retro-fitting Spring to an existing Servlet application. I want the servlets to have access to objects managed by Spring in the Application Context. There does not seem to be a way let Spring create the servlets and use IOC to give the servlets the needed objects. So my next best approach is to use the servlet init() methods to assign objects managed by Spring in the Application Context.

    So (finally!) my question, how do I get at the Application Context? I did some searching and all the approaches I saw involved loading the application context first, ex ClassPathXmlApplicationContext. I would like to get the existing context created by Spring at init time and use the getBean() method to wire up my servlets.

    Thanks,
    -=bill

  • #2
    Have you looked at WebApplicationContextUtils?
    http://www.springframework.org/docs/...textUtils.html

    Comment


    • #3
      karldmore,
      Thanks for the reply. I originally looked at WebApplicationContextUtils but I was confused by the fact that the method to get the context returns a WebApplicationContext so I thought I'd ask first.

      After reading your reply I used WebApplicationContextUtils and I was able to do what I wanted, so thanks again.

      I now see that WebApplicationContext implements ApplicationContext and represents an 'application context' for a web application.

      Comment


      • #4
        Fantastic Bill, glad the information was useful. If in doubt the reference manual is always worth a quick read, it covers most things.

        Comment

        Working...
        X