Springboot实践心得

Springboot实践心得

刚入门Springboot,跟着B站小匠视频学习,基本上照着敲,但是实践过程中可能是因为版本的问题,在调用Request的时候出现了以下问题。
附带B站小匠视频原版地址:https://www.bilibili.com/video/av50200264?spm_id_from=333.788.b_765f64657363.1
调用代码:

 @GetMapping("callback")
    public String callBack(@RequestParam(name = "code") String code,
                           @RequestParam(name = "state") String state,
                           HttpServletRequest request) {
        GitHubProvider gitHubProvider = new GitHubProvider();
        gitHubDo.setState(state);
        gitHubDo.setCode(code);
        gitHubDo.setClient_id(client_id);
        gitHubDo.setClient_secret(client_secret);
        gitHubDo.setRedirect_uri("http://localhost:10086/callback");
        String returnMsg = gitHubProvider.accessToken(gitHubDo);
        System.out.println(returnMsg);
        String returnAccess = returnMsg.split("&")[0];

        System.out.println(returnAccess);
        String accessToken = returnAccess.split("=")[1];
        System.out.println(accessToken);
        String vs = gitHubProvider.getAccessTokenInfo(accessToken);

        UserDao userDao = gitHubProvider.getUser(vs);
        System.out.println(userDao.toString());
        try {
            request.getSession().setAttribute("githubUser", userDao);

        } catch (Exception e) {//如果用户不存在
            request.getSession().setAttribute("githubUser", userDao);

            try {
            } catch (Exception ee) {
            }
        }
        return "redirect:/yhw";
    }

报错提示:

org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/] - Session event listener threw exception
java.lang.AbstractMethodError: org.apache.tomcat.websocket.server.WsSessionListener.sessionCreated(Ljavax/servlet/http/HttpSessionEvent;)V
at org.apache.catalina.session.StandardSession.tellNew(StandardSession.java:388) [tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.session.StandardSession.setId(StandardSession.java:360) [tomcat-embed-core-9.0.22.jar:9.0.22]

在这里插入图片描述

跟着提示看下去。中间过程debugger看,getSession()在没有Session的情况下会新建Session,也就是中间这一长串,效果等同于getSession(true).但是调用接口的sessionCreated的时候报错了,进去看到是个继承HttpSessionListner的类,按理来说没错,实在找不出问题,然后面向谷歌编程。
调用的接口
在这个老哥那里得到问题所在:
转自:https://blog.csdn.net/yanwenyuan0304/article/details/100514065
知道是版本的问题后

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:175)

The following method did not exist:

    org.apache.tomcat.util.modeler.Registry.disableRegistry()V

The method's class, org.apache.tomcat.util.modeler.Registry, is available from the following locations:

    jar:file:/C:/Users/lukawa/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.37/tomcat-embed-core-8.5.37.jar!/org/apache/tomcat/util/modeler/Registry.class

It was loaded from the following location:

    file:/C:/Users/lukawa/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.37/tomcat-embed-core-8.5.37.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.apache.tomcat.util.modeler.Registry

很明显是jar包里方法的问题,改class文件是不可能的了,然后直接从仓库里把9.X的core.jar拿过来名字改一下就OK了,改成8.X版本的名字,有点像自家的仔放别人家养的感觉,但是最后sessionCreated不报错了是真的!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值