Spring Boot是一个用于简化Spring应用程序开发的框架。它提供了一种快速构建可独立运行的、生产级别的Spring应用程序的方式。Spring Boot 2.1是Spring Boot的一个版本。
嵌入式Tomcat是Spring Boot默认的Web服务器,它可以将应用程序打包成一个可执行的JAR文件,并且内置了Tomcat容器,使得应用程序可以直接运行,而无需额外安装和配置外部的Web服务器。
HTTP/2是一种网络协议,它是HTTP协议的下一代版本。相比于HTTP/1.1,HTTP/2具有更高的性能和效率,可以实现多路复用、头部压缩、服务器推送等特性,从而提升Web应用的性能和用户体验。
SSL(Secure Sockets Layer)是一种用于保护网络通信安全的协议。它通过对网络通信进行加密和身份验证,确保数据在传输过程中不被窃取或篡改。在Web应用中,SSL常用于实现HTTPS协议,为网站提供安全的加密通信。
Gzip是一种数据压缩算法,可以将文本数据进行压缩,从而减小数据的传输大小,提高网络传输效率。在Web应用中,Gzip常用于压缩HTTP响应,减少网络传输的数据量,加快页面加载速度。
对于Spring Boot 2.1中带有HTTP/2和SSL的嵌入式Tomcat,gzip不工作的问题,可能是由于配置不正确或者缺少必要的依赖导致的。可以尝试以下解决方法:
server.http2.enabled=true
启用HTTP/2,使用server.ssl.enabled=true
启用SSL。<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-annotations-api</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper-el</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jsp-api</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-util</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-util-scan</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-websocket</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-websocket-api</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-websocket-client</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-websocket-server</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-websocket-servlet</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-websocket-api</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-websocket-client</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-websocket-server</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-websocket-servlet</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jni</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp-dbcp2</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp-pool2</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp-pool2-dbcp2</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp-pool2-dbcp2</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp-pool2-dbcp2</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp-pool2-dbcp2</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp-pool2-dbcp2</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp-pool2-dbcp2</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp-pool2-dbcp2</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp-pool2-dbcp2</artifactId>
<version>9.0.54</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp-pool2-dbcp2</artifactId>
<version>9.0.54</version>
</dependency>
server.compression.enabled=true
server.compression.mime-types=text/html,text/xml,text/plain,text/css,application/javascript,application/json
如果以上方法仍然无法解决问题,建议查阅Spring Boot官方文档、Tomcat官方文档以及相关技术论坛,寻求更详细的解决方案。
领取专属 10元无门槛券
手把手带您无忧上云