I have an instance of HandlerInterceptorAdapter
that intercept request to check locale...
public class LocaleControllerInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
final HttpSession session = SessionContextHolder.getSession();
// ...
}
}
and my SessionContextHolder
is :
public abstract class SessionContextHolder {
public static HttpSession getSession() {
ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
return attr.getRequest().getSession(true);
}
}
when I want to call an endpoint, the preHandle() method of the interceptor will called 2 times (why?!), in the first call, the session that SessionContextHolder
gives me (by getSession()
method) is an instance of org.apache.catalina.session.StandardSessionFacade
, and the second time is an instance of org.springframework.session.data.mongo.MongoExpiringSession
.
I've already enabled MongoHttpSession by @EnableMongoHttpSession
annotation.
The problem is that, I expect that the session should always be an instance of MongoExpiringSession
but is not.
Can anyone explain the mechanism of Spring-Session and the reason of this behavior?