会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132358个问题

项目代码.rar

运行

ErpApplication.java
SystemApplication.java

时都会报错

SystemApplication 会出现:

No bean of type 'org.apache.shiro.realm.Realm' found.


Action:


Please create bean of type 'Realm' or add a shiro.ini in the root classpath (src/main/resources/shiro.ini) or in the META-INF folder (src/main/resources/META-INF/shiro.ini).


ErpApplication会出现:


JAVA 全系列/第二十一阶段:分布式医疗云平台/项目环境搭建(旧) 76楼
JAVA 全系列/第二十一阶段:分布式医疗云平台/项目环境搭建(旧) 77楼
JAVA 全系列/第二十一阶段:分布式医疗云平台/系统管理前后端开发(旧) 78楼
JAVA 全系列/第二十一阶段:分布式医疗云平台/系统管理前后端开发(旧) 79楼
JAVA 全系列/第二十一阶段:分布式医疗云平台/项目环境搭建(旧) 80楼
JAVA 全系列/第二十一阶段:分布式医疗云平台/项目环境准备 82楼
JAVA 全系列/第二十一阶段:分布式医疗云平台/基础功能搭建 83楼
JAVA 全系列/第二十一阶段:分布式医疗云平台/项目环境搭建(旧) 84楼
JAVA 全系列/第二十一阶段:分布式医疗云平台/系统管理前后端开发(旧) 85楼
JAVA 全系列/第二十一阶段:分布式医疗云平台/项目环境准备 86楼

这个里面提示没有方法,这个方法应该在那里创建呢?

图片.png

图片.png

图片.png

图片.png

package com.bjsxt.config.shiro;
import com.bjsxt.domain.User;
import com.bjsxt.service.UserService;
import com.bjsxt.vo.ActiverUser;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
/**
 * @Author: GHP
 * 自定义 realm 去匹配用户名和密码
 */
public class UserRealm extends AuthorizingRealm {
    @Autowired
    @Lazy
    private UserService userService;
    @Override
    public String getName() {
        return this.getClass().getSimpleName();
    }
    /**
     * 做认证 --就是登陆
     * @param token
     * @return
    45
     * @throws AuthenticationException
     */
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws
            AuthenticationException {
//得到用户登陆名
        String phone=token.getPrincipal().toString();
//根据电话查询用户是否存在
        User user = userService.queryUserByPhone(phone);
        if(null!=user){//说明用户存在,但是密码可能不正确
//组装存放到 reids 里面的对象
            ActiverUser activerUser=new ActiverUser();
            activerUser.setUser(user);
//匹配密码
            SimpleAuthenticationInfo info=new SimpleAuthenticationInfo(
                    activerUser,user.getPassword(),
                    ByteSource.Util.bytes(user.getSalt()),this.getName()
            );
            return info;
        }else{
            return null;//代表用户不存在
        }
    }
    /**
     * 做授权 --登陆成功之后判断用户是否有某个菜单或按钮的权限
     * @param principals
     * @return
     */
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        ActiverUser activerUser= (ActiverUser) principals.getPrimaryPrincipal();//身份得到的就是上一个方法的返回值的值 第一个参数 activerUser
        SimpleAuthorizationInfo info=new SimpleAuthorizationInfo();
        return info;
    }
}


JAVA 全系列/第二十一阶段:分布式医疗云平台/系统管理前后端开发(旧) 89楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637