如何为RestController启用GZIP? [英] How to enable GZIP for RestController?

查看:199
本文介绍了如何为RestController启用GZIP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用spring的简单REST控制器. 返回的application/xml流的GZIP响应如何启用?

I'm having a simple REST controller using spring. How could GZIP response of the returned application/xml stream be enabled?

@RestController
public class MyRest {
    @RequestMapping(method = RequestMethod.GET,
            produces = MediaType.APPLICATION_XML_VALUE)
    @ResponseBody
    public ComplexRsp test() {
        //...
    }
}

使用soap + wsdl方法时,服务类上会有简单的@GZIP批注.如何为REST实现相同的目标?

When using soap+wsdl approach, there would be the simple @GZIP annotation on the service class. How can I achieve the same for REST?

推荐答案

如果您使用的是Spring Boot和Tomcat,则应该能够通过Tomcat配置来完成此任务: http ://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#how-to-enable-http-response-compression

If you are using Spring boot and Tomcat You should be able to accomplish this via Tomcat Configuration: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#how-to-enable-http-response-compression

这是类似的POST 将GZIP压缩与带有RESTful的Spring Boot/MVC/JavaConfig

Here is a similar POST Using GZIP compression with Spring Boot/MVC/JavaConfig with RESTful

它很简单,如下所示:

server.compression.enabled=true
server.compression.mime-types=application/xml

这篇关于如何为RestController启用GZIP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆