springboot内置tomcat服务器报错:

错误截图
错误截图

A cookie header was received [1604294699,1604294708; Hm_lpvt_bf373ec75d27891740b13e5a72c9d921=1604673321; void_pos=-1; c90eeba87a6753125fc6648af4d30f0d__void_post_views=46%2C105%2C69%2C64%2C76%2C140%2C119; 5bb9a040b78210db53ae2958ac0d21cf__void_post_views=16%2C46%2C61%2C91%2C18%2C4%2C85%2C25%2C73%2C76%2C95%2C105%2C33%2C10%2C7%2C9%2C69%2C116%2C31%2C14%2C8%2C119%2C64%2C13%2C24%2C131%2C132%2C140%2C141; 5bb9a040b78210db53ae2958ac0d21cf__typecho_uid=1; 5bb9a040b78210db53ae2958ac0d21cf__typecho_authCode=%24T%24broOWxF8j13ba0c1de5b245395cb0859bd60dcccb; SESSION=YzVlN2FmZWYtMDgxNC00YjQyLWFkYzYtNDlhODg2MWYzMWM2; 5bb9a040b78210db53ae2958ac0d21cf__typecho_all_comments=on] 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"的格式被视为非法
tomcat官方说明

可尝试解决方案:(配置tomcat)

方案1:

参考链接

import org.apache.tomcat.util.http.LegacyCookieProcessor;
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TomcatConfig {
    public WebServerFactoryCustomizer<TomcatServletWebServerFactory> cookieProcessorCustomizer() {
        return tomcatServletWebServerFactory -> tomcatServletWebServerFactory.addContextCustomizers((TomcatContextCustomizer) context -> {
            context.setCookieProcessor(new LegacyCookieProcessor());
        });
    }
}

方案二:

import org.apache.catalina.Context;
import org.apache.tomcat.util.http.LegacyCookieProcessor;
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.stereotype.Component;

@Component
public class EmbeddedTomcatConfig implements WebServerFactoryCustomizer {
    @Override
    public void customize(WebServerFactory factory) {
        ((TomcatServletWebServerFactory)factory).addContextCustomizers(new TomcatContextCustomizer() {
            @Override
            public void customize(Context context) {
                context.setCookieProcessor(new LegacyCookieProcessor());
            }
        });
    }
}