我有一个简单的REST
控制器使用spring
。
返回的GZIP响应如何application/xml
流是否启用?
@RestController
public class MyRest {
@RequestMapping(method = RequestMethod.GET,
produces = MediaType.APPLICATION_XML_VALUE)
@ResponseBody
public ComplexRsp test() {
//...
}
}
当使用soap+wsdl方法时,会有简单的@GZIP
服务类上的注释。我怎样才能在 REST 中实现同样的目标?
如果您使用 Spring boot 和 Tomcat,您应该能够通过 Tomcat 配置来完成此操作:http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#how-to-enable-http-response-compression http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#how-to-enable-http-response-compression
这是一个类似的帖子将 GZIP 压缩与 Spring Boot/MVC/JavaConfig 和 RESTful 一起使用 https://stackoverflow.com/questions/21410317/using-gzip-compression-with-spring-boot-mvc-javaconfig-with-restful
简单如下:
server.compression.enabled=true
server.compression.mime-types=application/xml
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)