SpringBoot整合Shiro时遇到的: No SecurityManager accessible to the calling code 错误

org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code

关于SpringBoot整合Shiro时遇到的:调用代码无法访问 SecurityManager 错误

我的解决方式:
在 
DefaultWebSecurityManager 类中添加以下代码

SecurityUtils.setSecurityManager(defaultWebSecurityManager);

//配置SecurityManager
    @Bean
    public DefaultWebSecurityManager defaultWebSecurityManager(){
        //创建 defaultWebSecurityManager 对象
        DefaultWebSecurityManager defaultWebSecurityManager = new DefaultWebSecurityManager();
        //创建加密对象 设置相关属性
        HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
        //采用md5加密
        hashedCredentialsMatcher.setHashAlgorithmName("md5");
        //采用迭代加密
        hashedCredentialsMatcher.setHashIterations(3);
        //将加密对象存储到 myRealm
        myRealm.setCredentialsMatcher(hashedCredentialsMatcher);
        //将myRealm存入defaultWebSecurityManager对象
        defaultWebSecurityManager.setRealm(myRealm);

        //将SecurityManager实例(这里是defaultWebSecurityManager)设置到SecurityUtils中。
        SecurityUtils.setSecurityManager(defaultWebSecurityManager);

        //返回
        return defaultWebSecurityManager;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值