错误:
o.apache.tomcat.util.http.parser.Cookie : A cookie header was received [1704716542,1704778481,1704890481] that contained an invalid cookie. That cookie will be ignored.
Note: further occurrences of this error will be logged at DEBUG level.
原因
大致问题就是从Tomcat 8,Cookie的解析已经符合RFC 6265。由于RFC 6265不再接受以前允许的逗号分隔符(例如RFC 2109) "Cookie:KEY 1 = VAL 1,KEY 2 = VAL 2"的格式所以被视为非法。
解决办法
在启动类上加入以下代码:
@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> cookieProcessorCustomizer() {
return tomcatServletWebServerFactory -> tomcatServletWebServerFactory.addContextCustomizers((TomcatContextCustomizer) context -> {
context.setCookieProcessor(new LegacyCookieProcessor());
});
}