当前位置: 代码迷 >> Web前端 >> shiro 中获取servletContext 跟WebApplicationContext
  详细解决方案

shiro 中获取servletContext 跟WebApplicationContext

热度:508   发布时间:2013-03-22 09:49:50.0
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());

?

  相关解决方案