Java Code Examples for org.springframework.web.context.support.StaticWebApplicationContext#getBean()
The following examples show how to use
org.springframework.web.context.support.StaticWebApplicationContext#getBean() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DelegatingFilterProxyTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testDelegatingFilterProxyWithTargetBeanName() throws ServletException, IOException { MockServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.registerSingleton("targetFilter", MockFilter.class); wac.refresh(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter"); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy("targetFilter"); filterProxy.init(new MockFilterConfig(sc)); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 2
Source File: DelegatingFilterProxyTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testDelegatingFilterProxyWithFilterName() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.registerSingleton("targetFilter", MockFilter.class); wac.refresh(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter"); MockFilterConfig proxyConfig = new MockFilterConfig(sc, "targetFilter"); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(); filterProxy.init(proxyConfig); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 3
Source File: DelegatingFilterProxyTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testDelegatingFilterProxyWithFilterName() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.registerSingleton("targetFilter", MockFilter.class); wac.refresh(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter"); MockFilterConfig proxyConfig = new MockFilterConfig(sc, "targetFilter"); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(); filterProxy.init(proxyConfig); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 4
Source File: DelegatingFilterProxyTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testDelegatingFilterProxyWithTargetBeanNameAndNotYetRefreshedApplicationContext() throws ServletException, IOException { MockServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.registerSingleton("targetFilter", MockFilter.class); // wac.refresh(); // note that the context is not set as the ROOT attribute in the ServletContext! DelegatingFilterProxy filterProxy = new DelegatingFilterProxy("targetFilter", wac); filterProxy.init(new MockFilterConfig(sc)); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter"); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 5
Source File: DelegatingFilterProxyTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testDelegatingFilterProxyWithFrameworkServletContext() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.registerSingleton("targetFilter", MockFilter.class); wac.refresh(); sc.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac); MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter"); MockFilterConfig proxyConfig = new MockFilterConfig(sc); proxyConfig.addInitParameter("targetBeanName", "targetFilter"); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(); filterProxy.init(proxyConfig); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 6
Source File: DelegatingFilterProxyTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testDelegatingFilterProxyWithFrameworkServletContext() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.registerSingleton("targetFilter", MockFilter.class); wac.refresh(); sc.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac); MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter"); MockFilterConfig proxyConfig = new MockFilterConfig(sc); proxyConfig.addInitParameter("targetBeanName", "targetFilter"); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(); filterProxy.init(proxyConfig); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 7
Source File: DelegatingFilterProxyTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testDelegatingFilterProxyWithFrameworkServletContext() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.registerSingleton("targetFilter", MockFilter.class); wac.refresh(); sc.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac); MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter"); MockFilterConfig proxyConfig = new MockFilterConfig(sc); proxyConfig.addInitParameter("targetBeanName", "targetFilter"); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(); filterProxy.init(proxyConfig); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 8
Source File: DelegatingFilterProxyTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testDelegatingFilterProxyNotInjectedWacServletAttrPreferred() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.refresh(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); sc.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac); StaticWebApplicationContext wacToUse = new StaticWebApplicationContext(); wacToUse.setServletContext(sc); String beanName = "targetFilter"; String attrName = "customAttrName"; wacToUse.registerSingleton(beanName, MockFilter.class); wacToUse.refresh(); sc.setAttribute(attrName, wacToUse); MockFilter targetFilter = (MockFilter) wacToUse.getBean(beanName); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(beanName); filterProxy.setContextAttribute(attrName); filterProxy.setServletContext(sc); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 9
Source File: DelegatingFilterProxyTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testDelegatingFilterProxyWithTargetFilterLifecycle() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.registerSingleton("targetFilter", MockFilter.class); wac.refresh(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter"); MockFilterConfig proxyConfig = new MockFilterConfig(sc); proxyConfig.addInitParameter("targetBeanName", "targetFilter"); proxyConfig.addInitParameter("targetFilterLifecycle", "true"); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(); filterProxy.init(proxyConfig); assertEquals(proxyConfig, targetFilter.filterConfig); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertEquals(proxyConfig, targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 10
Source File: DelegatingFilterProxyTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testDelegatingFilterProxyAndCustomContextAttribute() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.registerSingleton("targetFilter", MockFilter.class); wac.refresh(); sc.setAttribute("CUSTOM_ATTR", wac); MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter"); MockFilterConfig proxyConfig = new MockFilterConfig(sc); proxyConfig.addInitParameter("targetBeanName", "targetFilter"); proxyConfig.addInitParameter("contextAttribute", "CUSTOM_ATTR"); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(); filterProxy.init(proxyConfig); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 11
Source File: DelegatingFilterProxyTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testDelegatingFilterProxyInjectedPreferred() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.refresh(); sc.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac); StaticWebApplicationContext injectedWac = new StaticWebApplicationContext(); injectedWac.setServletContext(sc); String beanName = "targetFilter"; injectedWac.registerSingleton(beanName, MockFilter.class); injectedWac.refresh(); MockFilter targetFilter = (MockFilter) injectedWac.getBean(beanName); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(beanName, injectedWac); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 12
Source File: DelegatingFilterProxyTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testDelegatingFilterProxyAndCustomContextAttribute() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.registerSingleton("targetFilter", MockFilter.class); wac.refresh(); sc.setAttribute("CUSTOM_ATTR", wac); MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter"); MockFilterConfig proxyConfig = new MockFilterConfig(sc); proxyConfig.addInitParameter("targetBeanName", "targetFilter"); proxyConfig.addInitParameter("contextAttribute", "CUSTOM_ATTR"); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(); filterProxy.init(proxyConfig); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 13
Source File: DelegatingFilterProxyTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testDelegatingFilterProxyNotInjectedWithRootPreferred() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.refresh(); sc.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac); sc.setAttribute("another", wac); StaticWebApplicationContext wacToUse = new StaticWebApplicationContext(); wacToUse.setServletContext(sc); String beanName = "targetFilter"; wacToUse.registerSingleton(beanName, MockFilter.class); wacToUse.refresh(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wacToUse); MockFilter targetFilter = (MockFilter) wacToUse.getBean(beanName); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(beanName); filterProxy.setServletContext(sc); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 14
Source File: DelegatingFilterProxyTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testDelegatingFilterProxy() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.registerSingleton("targetFilter", MockFilter.class); wac.refresh(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter"); MockFilterConfig proxyConfig = new MockFilterConfig(sc); proxyConfig.addInitParameter("targetBeanName", "targetFilter"); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(); filterProxy.init(proxyConfig); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 15
Source File: DelegatingFilterProxyTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testDelegatingFilterProxyInjectedPreferred() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.refresh(); sc.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac); StaticWebApplicationContext injectedWac = new StaticWebApplicationContext(); injectedWac.setServletContext(sc); String beanName = "targetFilter"; injectedWac.registerSingleton(beanName, MockFilter.class); injectedWac.refresh(); MockFilter targetFilter = (MockFilter) injectedWac.getBean(beanName); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(beanName, injectedWac); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 16
Source File: DelegatingFilterProxyTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testDelegatingFilterProxyWithTargetFilterLifecycle() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.registerSingleton("targetFilter", MockFilter.class); wac.refresh(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter"); MockFilterConfig proxyConfig = new MockFilterConfig(sc); proxyConfig.addInitParameter("targetBeanName", "targetFilter"); proxyConfig.addInitParameter("targetFilterLifecycle", "true"); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(); filterProxy.init(proxyConfig); assertEquals(proxyConfig, targetFilter.filterConfig); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertEquals(proxyConfig, targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 17
Source File: DelegatingFilterProxyTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testDelegatingFilterProxyNotInjectedWacServletAttrPreferred() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.refresh(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); sc.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac); StaticWebApplicationContext wacToUse = new StaticWebApplicationContext(); wacToUse.setServletContext(sc); String beanName = "targetFilter"; String attrName = "customAttrName"; wacToUse.registerSingleton(beanName, MockFilter.class); wacToUse.refresh(); sc.setAttribute(attrName, wacToUse); MockFilter targetFilter = (MockFilter) wacToUse.getBean(beanName); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(beanName); filterProxy.setContextAttribute(attrName); filterProxy.setServletContext(sc); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 18
Source File: DelegatingFilterProxyTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testDelegatingFilterProxyNotInjectedWithRootPreferred() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.refresh(); sc.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac); sc.setAttribute("another", wac); StaticWebApplicationContext wacToUse = new StaticWebApplicationContext(); wacToUse.setServletContext(sc); String beanName = "targetFilter"; wacToUse.registerSingleton(beanName, MockFilter.class); wacToUse.refresh(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wacToUse); MockFilter targetFilter = (MockFilter) wacToUse.getBean(beanName); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(beanName); filterProxy.setServletContext(sc); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 19
Source File: DelegatingFilterProxyTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testDelegatingFilterProxyInjectedPreferred() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.refresh(); sc.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac); StaticWebApplicationContext injectedWac = new StaticWebApplicationContext(); injectedWac.setServletContext(sc); String beanName = "targetFilter"; injectedWac.registerSingleton(beanName, MockFilter.class); injectedWac.refresh(); MockFilter targetFilter = (MockFilter) injectedWac.getBean(beanName); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(beanName, injectedWac); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }
Example 20
Source File: DelegatingFilterProxyTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testDelegatingFilterProxy() throws ServletException, IOException { ServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.registerSingleton("targetFilter", MockFilter.class); wac.refresh(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter"); MockFilterConfig proxyConfig = new MockFilterConfig(sc); proxyConfig.addInitParameter("targetBeanName", "targetFilter"); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(); filterProxy.init(proxyConfig); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filterProxy.doFilter(request, response, null); assertNull(targetFilter.filterConfig); assertEquals(Boolean.TRUE, request.getAttribute("called")); filterProxy.destroy(); assertNull(targetFilter.filterConfig); }