开发者社区> FightingHeart> 正文

SpringBoot集成shiro在securityUtils.getSubject()报错No SecurityManager accessible to the calling code,该怎么解决呢?

简介: 在做一个springboot+shiro的demo,但是在用户登录的方法中securityUtils.getSubject()时报错: org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.
+关注继续查看

在做一个springboot+shiro的demo,但是在用户登录的方法中securityUtils.getSubject()时报错:
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.不知道怎么解决,请问有大神可以帮助吗?

下面是shiro配置类:
@Configuration
public class ShiroConfig {

@Bean
public ShiroFilterFactoryBean getBean(@Qualifier("securityManager") DefaultWebSecurityManager securityManager){
    ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
    bean.setSecurityManager(securityManager);
    bean.setLoginUrl("/login");
    bean.setSuccessUrl("/mainMenu");
    Map<String,String> filterMap = new LinkedHashMap<>();
    filterMap.put("/login","anon");
    filterMap.put("/*","authc");
    bean.setFilterChainDefinitionMap(filterMap);
    return bean;
}

@Bean("securityManager")
public DefaultWebSecurityManager getSecurityManage(@Qualifier("accountRealm")AccountRealm accountRealm){
    DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
    securityManager.setRealm(accountRealm);
    return securityManager;
}

@Bean("accountRealm")
public AccountRealm getAccountRealm(){
    return new AccountRealm();
}

}
_

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
Springboot整合Shiro
Springboot整合Shiro
14 0
【异常】解决springboot项目shiro框架下的AppScan漏洞会话标识未更新问题
解决springboot项目shiro框架下的AppScan漏洞会话标识未更新问题
69 0
SpringBoot集成shiro认证,实现Shiro认证的登录操作
SpringBoot集成shiro认证,实现Shiro认证的登录操作
82 0
【SpringBoot技术指南】「权限校验专区」Shiro整合JWT授权和认证实现
【SpringBoot技术指南】「权限校验专区」Shiro整合JWT授权和认证实现
122 0
+关注
FightingHeart
一只菜鸟小码农
文章
问答
视频
文章排行榜
最热
最新
相关电子书
更多
Grand Launch of Cloud Security
立即下载
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载