Springboot整合Shiro报 UnavailableSecurityManagerException异常的处理
Springboot整合Shiro报 UnavailableSecurityManagerException异常的处理org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro
·
Springboot整合Shiro报 UnavailableSecurityManagerException异常的处理
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.
at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123)
at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:626)
at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56)
在Springboot整合Shiro报以上错误,千万别划走了。
以上错误是在Springboot整合Shiro时报的一个错误,该错误的意思是:
不可用的SecurityManager异常:
调用代码无法访问SecurityManager,无论是绑定到org.apache.shiro.util.ThreadContext还是作为vm静态单例。这是无效的应用程序配置。位于org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123)
发生此错误的主要原因在于,我们在SpringBoot中创建Shiro的安全管理器对象securityMannger对象时,要么绑定到ThreadContext中,要么作为虚拟机的静态单例。
导致此错误的主要原因是,我们在配置SecurityManager bean时,没有手动绑定securityMannger对象,如下:
// 安全管理器对象创建
@Bean
public SecurityManager securityManager(EmployeeRealm employeeRealm) {
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
securityManager.setRealm(employeeRealm);
ThreadContext.bind(securityManager);
return securityManager;
}
这样问题就解决了。
更多推荐
已为社区贡献1条内容
所有评论(0)