我的解决方案受Rob Winch的回答启发。尽管在我的场景中,Spring 正在 保存已
X-Requested-With:XMLHttpRequest设置的请求。这些是我不得不忽略的要求。
我创建了一个类作为自定义
RequestCache类。
@Service("customRequestCache")public class CustomRequestCache extends HttpSessionRequestCache { //this class (bean) is used by spring security @Override public void saveRequest(HttpServletRequest request, HttpServletResponse response) { if (!"XMLHttpRequest".equalsIgnoreCase(request.getHeader("X-Requested-With"))) { //request is not ajax, we can store it super.saveRequest(request, response); } else { //do nothing, add some logs if you want } }}然后,在我的spring安全配置中:
<http> <request-cache ref="customRequestCache" /></http>
使用此自定义请求缓存类后,不再存储ajax请求。



