RestTemplateConfig.java 828 B

1234567891011121314151617181920212223
  1. package com.macro.mall.tiny.config;
  2. import org.springframework.context.annotation.Bean;
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
  5. import org.springframework.http.converter.StringHttpMessageConverter;
  6. import org.springframework.web.client.RestTemplate;
  7. import java.nio.charset.StandardCharsets;
  8. /**
  9. * RestTemplate配置类
  10. */
  11. @Configuration
  12. public class RestTemplateConfig {
  13. @Bean
  14. public RestTemplate restTemplate() {
  15. RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory()); // 使用HttpClient,支持GZIP
  16. restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8)); // 支持中文编码
  17. return restTemplate;
  18. }
  19. }