Skip to content

Instantly share code, notes, and snippets.

@samuelstein
Created February 22, 2023 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelstein/84b9e956ec4af401b7d1b6012c47e160 to your computer and use it in GitHub Desktop.
Save samuelstein/84b9e956ec4af401b7d1b6012c47e160 to your computer and use it in GitHub Desktop.
Spring Boot RestTemplate with GZIP Support
package de.samuelstein.project.configuration;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
@Primary
@Getter
@Setter
@Component
@ToString
@ConfigurationProperties(prefix = "app.backend")
public class AppConfiguration {
@Bean
public RestTemplate getRestTemplateWithGzipSupport() {
// supports gzip
final var clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(
HttpClientBuilder.create().build());
return new RestTemplate(clientHttpRequestFactory);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment