How to enable GZIP for RestController? [duplicate]

浪子不回头ぞ 提交于 2020-01-02 07:27:12

问题


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() {
        //...
    }
}

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


回答1:


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

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

It's as simple as follows:

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


来源:https://stackoverflow.com/questions/28557165/how-to-enable-gzip-for-restcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!