错误的初始化方式导致用户被踢下线

出现原因

项目中代码会出现此种情况,多次请求会出现并发问题,导致request获取不到,用户被踢下线,需要正确使用@Autowired的注入

1
2
3
4
5
6
7
8
private HttpServletRequest request;
private HttpServletResponse response;

@ModelAttribute
public void init(HttpServletRequest request, HttpServletResponse response) {
this.request = request;
this.response = response;
}

修复问题

改用直接注入的方式获取request、response

1
2
3
4
@Autowired
private HttpServletRequest request;
@Autowired
private HttpServletResponse response;