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.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在securityUtils.getSubject()报错No SecurityManager accessible to the calling code,该怎么解决呢?

上一篇:用Helm部署Kubernetes应用,支持多环境部署与版本回滚


下一篇:CSS的引入与选择器