在Servlet和filter中得到WAC

1)在servlet中wac
public void init(ServletConfig config) throws ServletException {
		super.init(config);
	WebApplicationContext	wac = WebApplicationContextUtils
				.getWebApplicationContext(getServletContext());
 XXXService service = (XXXService) wac
                .getBean("beanName");
	}


2)在filter得到wac,
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
    {		
	WebApplicationContext	wac = WebApplicationContextUtils
				.getWebApplicationContext(request.getSession().getServletContext());
 XXXService service = (XXXService) wac
                .getBean("beanName");
	}

你可能感兴趣的:(servlet)