Spring-RestTemplate扩展性原理

目标

简介RestTemplate,以图示方式直观展示RestTemplate扩展性原理。

what

执行http请求的同步客户端。

基于其他http client库,restTemplate提供了简单的模板化的API。其他http client库,如JDK HttpURLConnection、Apache HttpComponents、okHttp3等。

为多种http method场景提供了模板化API,也可使用exchange和excute处理低频场景。

RestTemplate未来计划,不会再添加新特性,且在Spring未来版本中将会被废弃。

Spring5.0之后,提供了restTemplate的替代方案,即org.springframework.web.reactive.client.WebClient。具有如下特性:non-blocking、reactive、sync、async、streaming。

类关系

Spring-RestTemplate扩展性原理Spring-RestTemplate扩展性原理

扩展性

从spring实现扩展性的一般原理出发,就可以得出RestTemplate的扩展性方案。

Spring-RestTemplate扩展性原理 

通过下图可以看到,spring对一些支持的类库提供了Factory实现。

Spring-RestTemplate扩展性原理 Spring-RestTemplate扩展性原理

 

上述是实现扩展性的通用方案,抽象、面向接口编程、接口引用指向子类对象。