如何在SpringBoot中实现RestTemplate

发布时间:2021-05-27 18:10:59 作者:Leah
来源:亿速云 阅读:119

这篇文章给大家介绍如何在SpringBoot中实现RestTemplate,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

RestTemplate的多种实现

使用JDK默认的http library

使用Apache提供的httpclient

使用Okhttp3

@Configuration
public class RestConfig {

  @Bean
  public RestTemplate restTemplate(){
    RestTemplate restTemplate = new RestTemplate();
    return restTemplate;
  }

  @Bean("urlConnection")
  public RestTemplate urlConnectionRestTemplate(){
    RestTemplate restTemplate = new RestTemplate(new SimpleClientHttpRequestFactory());
    return restTemplate;
  }

  @Bean("httpClient")
  public RestTemplate httpClientRestTemplate(){
    RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
    return restTemplate;
  }

  @Bean("OKHttp3")
  public RestTemplate OKHttp3RestTemplate(){
    RestTemplate restTemplate = new RestTemplate(new OkHttp3ClientHttpRequestFactory());
    return restTemplate;
  }
}

关于如何在SpringBoot中实现RestTemplate就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. 31. Springboot中使用RestTemplate
  2. 如何在Springboot中使用RestTemplate

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

springboot resttemplate

上一篇:使用Spring Security怎么实现登录验证码

下一篇:使用spring Cloud怎么实现微服务跨域

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》