75.13 使用Tomcat的LegacyCookieProcessor

默认的,Spring Boot使用的内嵌Tomcat不能支持Version 0的Cookie格式,你可能会看到以下错误:

java.lang.IllegalArgumentException: An invalid character [32] was present in the Cookie value

可以的话,你需要考虑将代码升级到只存储遵从最新版Cookie定义的值。如果不能改变写入的cookie,你可以配置Tomcat使用LegacyCookieProcessor。通过向WebServerFactoryCustomizerbean添加一个TomcatContextCustomizer可以开启LegacyCookieProcessor

@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> cookieProcessorCustomizer() {
return (factory) -> factory.addContextCustomizers(
(context) -> context.setCookieProcessor(new LegacyCookieProcessor()));
}