Accessing Spring beans from servlet filters and tags

前端 未结 4 2011
南方客
南方客 2020-12-28 14:50

I can access Spring beans in my Servlets using

WebApplicationContext springContext = 
    WebApplicationContextUtils.getWebApplicationContext(getServle         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-28 15:16

    For filters - use Filter.init():

    public void init(FilterConfig config) {
        WebApplicationContext springContext = 
            WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
    }
    

    For tags - use TagSupport.pageContext (note that it's not available in SimpleTagSupport):

    WebApplicationContext springContext = 
        WebApplicationContextUtils.getWebApplicationContext(pageContext.getServletContext());
    

提交回复
热议问题