读书人

shiro 中获取servletContext 跟WebApp

发布时间: 2013-03-22 09:49:50 作者: rapoo

shiro 中获取servletContext 和WebApplicationContext

项目中用到shiro管理权限,但是shiro在spring容器中,某些类不在spring中初始化,但是想得到spring容器管理的bean,或者从shiro中获取servletContext,如下

ServletRequest request = ((WebSubject)SecurityUtils.getSubject()).getServletRequest(); HttpSession httpSession = ((HttpServletRequest)request).getSession(); logger.debug("httpSession.getServletContext():"+httpSession.getServletContext());context = WebApplicationContextUtils.getWebApplicationContext(httpSession.getServletContext());

?

读书人网 >Web前端

热点推荐