我使用REST
设置了一个简单的spring
控制器。
如何启用返回的application/xml
流的GZIP响应?
@RestController
public class MyRest {
@RequestMapping(method = RequestMethod.GET,
produces = MediaType.APPLICATION_XML_VALUE)
@ResponseBody
public ComplexRsp test() {
//...
}
}
使用soap + wsdl方法时,服务类上会有简单的@GZIP
注释。如何为REST实现相同的目标?
答案 0 :(得分:11)
如果您正在使用Spring启动和Tomcat您应该能够通过Tomcat配置完成此任务: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#how-to-enable-http-response-compression
这是一个类似的POST Using GZIP compression with Spring Boot/MVC/JavaConfig with RESTful
这很简单如下:
server.compression.enabled=true
server.compression.mime-types=application/xml