报错No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.Threa

7 篇文章 0 订阅
1 篇文章 0 订阅

本人在开发现在的web项目中的时候,碰到了一个问题,大概就是说调用不到SecurityManager。报错的是其中一个Controller,上网查了一下,看了下代码,定位到了类的开头定义的一个通过Shiro获取用户的登录名的变量。一开始以为我是因为final关键字不能修饰session这种动态的变量。后面删除final也没有变化还是报错。之后我把从Shiro获取用户名删掉,只用字符串的时候就可以运行了。

报错代码:

private static final String REDIS_KEY =  ShiroUtils.getLoginName() + "12345";

推测是因为当在类的开头获取登录名的时候,Controller只有在方法内,即处理转发用户请求时才会有Shiro.session的作用域,不在方法内获取的Shiro.session并不知道你是哪个用户,方法外并没有他的作用域,也就没有session了,因此报了这个错误。

完整报错如下:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxController' defined in file [xxxController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.xxx.xxxController]: Constructor threw exception; nested exception is 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.

 

参考博客:https://blog.csdn.net/catoop/article/details/63257702

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值