membersound membersound - 7 months ago 754
Java Question

How to enable GZIP for RestController?

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?

Answer

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.tomcat.compression=on
server.tomcat.compressableMimeTypes=application/xml
Comments