gpt4 book ai didi

java - 如何在没有 xml 的 Spring MVC 中启用 REST gzip 压缩?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:46:29 24 4
gpt4 key购买 nike

那里有一些过滤器,但没有可用的纯 Java 解决方案或一些有用的库。我将 Spring MVC 与 Tomcat 一起使用并将发布部署到 Heroku(因此无法更改 servlet 容器配置)。如何在没有 XML 的情况下在 Spring MVC 中启用 REST gzip 压缩?

最佳答案

您可以设置在您的 servlet 容器上使用压缩的规则,例如您可以使用压缩属性的 apache-tomcat。来自 documentation :

compression

The Connector may use HTTP/1.1 GZIP compression in an attempt to save server bandwidth. The acceptable values for the parameter is "off" (disable compression), "on" (allow compression, which causes text data to be compressed), "force" (forces compression in all cases), or a numerical integer value (which is equivalent to "on", but specifies the minimum amount of data before the output is compressed). If the content-length is not known and compression is set to "on" or more aggressive, the output will also be compressed. If not specified, this attribute is set to "off".

Note: There is a tradeoff between using compression (saving your bandwidth) and using the sendfile feature (saving your CPU cycles). If the connector supports the sendfile feature, e.g. the NIO connector, using sendfile will take precedence over compression. The symptoms will be that static files greater that 48 Kb will be sent uncompressed. You can turn off sendfile by setting useSendfile attribute of the connector, as documented below, or change the sendfile usage threshold in the configuration of the DefaultServlet in the default conf/web.xml or in the web.xml of your web application.

compressionMinSize

If compression is set to "on" then this attribute may be used to specify the minimum amount of data before the output is compressed. If not specified, this attribute is defaults to "2048".

关于java - 如何在没有 xml 的 Spring MVC 中启用 REST gzip 压缩?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24969577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com