首页 > 解决方案 > How to enable GZIP compression in Spring MVC with annotation on a controller class/method

问题描述

I'm researching migration from JAX-RS to Spring MVC and I stuck with GZIP.

In Apache CXF (one of JAX-RS implementation) it's possible to use @GZIP annotation at controller level that indicates that all resources in this class will be gzipped. From documentation:

This class is used to control GZIP compression of messages. Attaching this feature to an endpoint will allow the endpoint to handle compressed requests, and will cause outgoing responses to be compressed if the client indicates (via the Accept-Encoding header) that it can handle them.

I can't find how to do the same easily in Spring MVC. gzip is not mentioned in official documentation and answers like Using GZIP compression with Spring Boot/MVC/JavaConfig with RESTful show solutions for Spring Boot (not Spring MVC) that are application-wide (should be only for certain controllers).

Is there a simple solution for Spring MVC to enable GZIP compression by using annotation on a controller class/method. (maybe via custom message converter?)

标签: spring-mvcgzip

解决方案


推荐阅读