SpringBoot项目中Shrio报No SecurityManager,错误信息如下
错误信息:
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.
检查了所有都有@Bean注释,但还是报这个
解决办法:
找Shrio的配置类,比如ShiroConfiguration.java,找到配置securityManager的方法,加上ThreadContext.bind(securityManager);
@Bean
public SecurityManager securityManager() {
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
securityManager.setRealm(getWJRealm());
ThreadContext.bind(securityManager);//加上这句代码手动绑定
securityManager.setRememberMeManager(rememberMeManager());
return securityManager;
}