1 @Bean 2 public ResourceConfig resourceConfig() { 3 ResourceConfig resourceConfig = new ResourceConfig(); 4 5 // 开启gzip压缩支持请求 6 resourceConfig.register(GZipEncoder.class); 7 // 开启gzip压缩支持响应(依赖的包:org.glassfish.jersey.ext:jersey-entity-filtering:2.27) 8 resourceConfig.register(EntityFilteringFeature.class); 9 EncodingFilter.enableFor(resourceConfig, GZipEncoder.class); 10 11 return resourceConfig; 12 }
<dependency> <groupId>org.glassfish.jersey.ext</groupId> <artifactId>jersey-entity-filtering</artifactId> <version>2.27</version> </dependency>