【问题标题】:Setting Spring Boot property server.compression.enabled to true doesn't get applied to the autoconfigured Tomcat Server将 Spring Boot 属性 server.compression.enabled 设置为 true 不会应用于自动配置的 Tomcat 服务器
【发布时间】:2019-04-27 16:31:15
【问题描述】:

我正在使用 Spring Boot 2.0.6.RELEASE 并试图让内部 Tomcat 服务器对我正在处理的 API 的响应进行 GZip。根据 spring boot 文档 https://docs.spring.io/spring-boot/docs/2.0.6.RELEASE/reference/htmlsingle/#how-to-enable-http-response-compression 添加 server.compression.enabled=true 到 application.properties 应该启用嵌入式 Web 服务器的压缩。

但是,我从 API 获得的响应看起来并没有被压缩。

我已经关注了这个问题Spring boot response compression not working,并且在应用程序启动时检查 ServerProperties 的 Compression 对象时,似乎已启用的属性设置为 false。

我在这里错过了什么?

【问题讨论】:

    标签: java spring-boot tomcat compression gzip


    【解决方案1】:

    使用如下压缩指定mime-types

    server.compression.enabled=true
    server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain
    

    【讨论】:

    • 试过没有成功。根据文档,这些 mime 类型包含在默认 mime-types 中。
    • @Kasum,你在spring boot中使用的是哪个应用服务器,默认是(tomcat)还是你改了?
    • 这是默认的tomcat服务器
    • 您需要在 Tomcat 中进行配置。应用服务器接管。如果您在 Tomcat 前面有 apache 服务器。也需要在 Apache 中启用它
    【解决方案2】:

    如果启用了强 Etag,则禁用压缩。我使用的是 ShallowEtagHeaderFilter,一旦我删除它,压缩就开始工作了。

    【讨论】:

      猜你喜欢
      • 2015-12-21
      • 2015-11-21
      • 2017-05-23
      • 2019-04-21
      • 2015-09-15
      • 1970-01-01
      • 2016-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多