Created
February 22, 2023 20:02
-
-
Save samuelstein/84b9e956ec4af401b7d1b6012c47e160 to your computer and use it in GitHub Desktop.
Spring Boot RestTemplate with GZIP Support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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