Announcement Announcement Module
No announcement yet.
How to access DispatcherServlet's context from another Servlet? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to access DispatcherServlet's context from another Servlet?

    Basically what I'm trying to do is to add Spring-based services into an existing servlet application. I'm not really happy about the idea of destroying the current architecture, so it would be better for me to leave it, and to add Spring DispatcherServlet which would initialize all the beans for me.

    The problem I'm facing with is that I can't see a way to access DispatcherServlet's context from another Servlet. It seems that RequestContextUtils and WebApplicationContextUtils classes are of little help here, so maybe someone will point me to some other way of working this out?

    Of course, I understand that I can initialize Spring by hand in my legacy servlet and don't use DispatcherServlet at all, but it's really interesting for me to know is there a solution that gets pre-initialized context from spring servlet.

    Thanks in advance!

  • #2
    Why not use ContextLoaderListener to load the context, which will then be accessible through WebApplicationContextUtils from anywhere in the same web app?


    • #3
      Thanks alot! Quite easy, but it helped!