如何为RestController启用GZIP? [英] How to enable GZIP for RestController?
问题描述
我有一个使用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屋!