• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

org.apache.shiro.UnavailableSecurityManagerException: No Sec

mysql 搞代码 4年前 (2022-01-09) 15次浏览 已收录 0个评论

关于shiro错误的分析 错误提示: org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code,either boun本文来源gaodai#ma#com搞*!代#%^码网%d to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid a

关于shiro错误的分析
错误提示:

org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code,either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration.

错误原因:

在web.xml中配置shiro filter的时候,shiro filter放置位置放到了struts2 filter后面

原因分析:

如果使用struts2,那么在struts2加载静态资源的时候,需要将静态资源SecurityUtils也加载进去,如果将shiro filter放置位置放到了struts2 filter后面,那么必将导致无法加载到struts2中去,而后使用SecurityUtils.getSubject();的时候,导致出错,

解决办法:

shiro的filter应该放在struts2的 filter的上面

还可以在使用之前使用这种方式:即在SecurityUtils.getSubject();之前加入如下代码

Factory factory = new IniSecurityManagerFactory("classpath:shiro.ini");// 创建SecurityManager (根据配置创建SecurityManager实例)SecurityManager security = factory.getInstance();SecurityUtils.setSecurityManager(security);

这个想必不用解释了吧


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:org.apache.shiro.UnavailableSecurityManagerException: No Sec

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址