WebMvcConfigurer配置关闭session
时间: 2024-06-12 13:10:30 浏览: 48
CodeIgniter配置之SESSION用法实例分析
可以通过实现WebMvcConfigurer接口的addInterceptors方法来关闭session。具体实现如下:
```java
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new HandlerInterceptorAdapter() {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
HttpSession session = request.getSession(false);
if (session != null) {
session.invalidate();
}
return true; }
});
}
}
```
阅读全文