大家都是如何处理后台 tomcat 重启导致session失效,接口请求不成功需要重新登录的问题的?

小程序 文章 2021-03-29 11:42 1268 0 全屏看文

AI助手支持GPT4.0

大家都是如何处理后台 tomcat 重启导致session失效,接口请求不成功需要重新登录的问题的?How do you deal with the problem of session failure due to tomcat restart in the background, and re-login required for unsuccessful interface requests?

大家都是如何处理后台 tomcat 重启导致session失效,接口请求不成功需要重新登录的问题的?

小程序已经正式上线,但是一直有个问题困扰着我。请处理过这类问题的前辈能不吝赐教

问题描述:

我是负责前端开发的,由于某些需求变动,后台(java)需要频繁的修改,修改完之后后台负责把代码部署上线。据后台开发说,后台部署代码到服务器后需要重启tomcat,重启后会导致给前端分发的session失效。如果此时用户正在访问某个页面,而前端把失效的 session 通过接口发送给后台,就会导致数据请求失败,非常影响用户体验。

不知道大家都是怎么处理这类问题的,想请教下大家的处理方式

Small program has been officially launched, but there has been a problem bothering me. I am responsible for the front-end development. Due to some requirements changes, the background (Java) needs to be modified frequently. After modification, the background is responsible for deploying the code online. According to the background development, Tomcat needs to be restarted after the background code is deployed to the server, which will lead to the failure of the session distributed to the front end. If the user is visiting a page at this time, and the front end sends the invalid session to the background through the interface, the data request will fail, which greatly affects the user experience. I don't know how we all deal with this kind of problem. I would like to ask you how to deal with it

回答:

鲤子:用token,可以持续化保存,存数据库,redis,本地缓存等,就算服务重启也没事,token只会在登陆态失效了才失去作用。
.:

修改tomcat的配置文件"conf/context.xml"  ,去掉<Manager pathname="" />和<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />的注释,然后删除work文件夹,再重启服务器的时候,就会不保留session

Mr.Zhao:

问你们负责人

:大佬是怎么处理这个问题的?我们没有负责人
Mr.Zhao:别用session
:不用 session 不会有问题吗?后台分配 sessionId 给前端,我的理解是:
1. 做用户登录状态保持
2. 一定程度上保证接口调用的安全性
Mr.Zhao:坐登录态也没必要用session,session跟接口安全性没关系。必须要session,可以结合redis,那是后端的事情

-EOF-

AI助手支持GPT4.0