Announcement Announcement Module
Collapse
No announcement yet.
How to get beans from ContextLoaderPlugIn in a Filter? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get beans from ContextLoaderPlugIn in a Filter?

    Hi I'm using the ContextLoaderPlugin to hold my AppContext.. its being initialized as a struts plugin. Is there an easy way for me to get some beans from that context from a Filter?
    Thanks,
    David

  • #2
    ContextLoaderPlugin registers a WebApplicationContext into ServletContext under attribute ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX. You can use the following code to fetch WebApplicationContext from the ServletContext into your filter:
    Code:
      ServletContext sc = filterConfig.getServletContext();
      WebApplicationContext wac = (WebApplicationContext)
    				sc.getAttribute(ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX);
    HTH

    Comment


    • #3
      In Acegi Security we use filters all over the place that require collaborators defined in the application context. We also need to check they're wired up correctly. You might like to check the net.sf.acegisecurity.util.FilterToBeanProxy class, which lets you filter actually live within the application context. It's a general-purpose class (used by other people as well) which I think would be a good addition to Spring Core.

      Comment

      Working...
      X