org.apache.tomcat.util.http.parser.Cookie.logInvalidHeader A cookie header was received

在启动项目时遇到logInvalidHeader 的警告,当然不影响系统的运行,

先说问题来源: 是因为新版tomcat的cookie处理warn比老版严格造成,由tomcat6升级到tomcat8就会有这个问题。

[http-nio-8080-exec-5] org.apache.tomcat.util.http.parser.Cookie.logInvalidHeader A cookie header was received [XX] that contained an invalid cookie. That cookie will be ignored.Note: further occurrences of this error will be logged at DEBUG level.
解决方法:添加LegacyCookieProcessor文件来替代默认的cookie设置。(cookie解析器)

cat /usr/local/apache-tomcat-8.5.12/conf/context.xml 
<?xml version="1.0" encoding="UTF-8"?>
<!-- The contents of this file will be loaded for each web application -->
<Context>

    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

    <!--
    <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor" />
    -->

    <CookieProcessor className="org.apache.tomcat.util.http.LegacyCookieProcessor" />

</Context>

Rfc6265CookieProcessor这个配置不管用,问题出处:

https://stackoverflow.com/questions/36665320/a-cookie-header-was-received-that-contained-an-invalid-cookie

https://www.cnblogs.com/passedbylove/p/7587142.html#4166573

配置方案LegacyCookieProcessor说明:

https://tomcat.apache.org/tomcat-8.5-doc/config/cookie-processor.html#Legacy_Cookie_Processor_-_org.apache.tomcat.util.http.LegacyCookieProcessor