spring 中获取 servletcontext

阅读更多
今天使用security进行权限控制时,需要用到application中的数据,但是发现无法使用strust2中的actioncontext获取。
个人猜测可能是由于security运行在strust2之前,strust2还未能注册当前请求的ActionContext,所以无法使用它获取application。
下面为spring 中 通过 contextLoader 获取servletcontext的方法:

WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();   
        ServletContext servletContext = webApplicationContext.getServletContext(); 

你可能感兴趣的:(spring,java,servletcontext)