日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Springboot实践心得

發布時間:2024/3/12 javascript 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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()VThe 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.classIt 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.jarAction: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不報錯了是真的!

總結

以上是生活随笔為你收集整理的Springboot实践心得的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。