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
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
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:
HTHCode:ServletContext sc = filterConfig.getServletContext(); WebApplicationContext wac = (WebApplicationContext) sc.getAttribute(ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX);
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.