我有HandlerInterceptorAdapter
的实例拦截检查区域设置的请求...
public class LocaleControllerInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
final HttpSession session = SessionContextHolder.getSession();
// ...
}
}
我的SessionContextHolder
是:
public abstract class SessionContextHolder {
public static HttpSession getSession() {
ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
return attr.getRequest().getSession(true);
}
}
当我想调用端点时,拦截器的preHandle()方法会在第一次调用中调用2次(为什么?!),SessionContextHolder
给我的会话(getSession()
} method)是org.apache.catalina.session.StandardSessionFacade
的实例,第二次是org.springframework.session.data.mongo.MongoExpiringSession
的实例。
我已经通过@EnableMongoHttpSession
注释启用了MongoHttpSession。
问题是,我希望会话应始终是MongoExpiringSession
的实例,但事实并非如此。
任何人都可以解释Spring-Session的机制以及这种行为的原因吗?