|
11 | 11 | [ ](https://img.ljcdn.com/hc-picture/6302d742-ebc8-4649-95cf-62ccf57a1add)
|
12 | 12 |
|
13 | 13 |
|
14 |
| -`Retrofit`是适用于`Android`和`Java`且类型安全的HTTP客户端,其最大的特性的是**支持通过`接口`的方式发起HTTP请求**。而`spring-boot`是使用最广泛的Java开发框架,但是`Retrofit`官方没有支持与`spring-boot`框架快速整合,因此我们开发了`retrofit-spring-boot-starter`。 |
15 |
| - |
16 | 14 | **`retrofit-spring-boot-starter`实现了`Retrofit`与`spring-boot`框架快速整合,并且支持了诸多功能增强,极大简化开发**。
|
17 | 15 |
|
18 |
| -🚀项目持续优化迭代,欢迎大家提ISSUE和PR!麻烦大家能给一颗star✨,您的star是我们持续更新的动力! |
| 16 | +> 🚀项目持续优化迭代,欢迎大家提ISSUE和PR!麻烦大家能给一颗star✨,您的star是我们持续更新的动力! |
19 | 17 |
|
20 | 18 | github项目地址:[https://github.com/LianjiaTech/retrofit-spring-boot-starter](https://github.com/LianjiaTech/retrofit-spring-boot-starter)
|
21 | 19 |
|
@@ -54,8 +52,6 @@ gitee项目地址:[https://gitee.com/lianjiatech/retrofit-spring-boot-starter]
|
54 | 52 | </dependency>
|
55 | 53 | ```
|
56 | 54 |
|
57 |
| -> **强烈建议使用最新版本,稳定无bug!** |
58 |
| -
|
59 | 55 | **本项目依赖Retrofit-2.9.0,okhttp-3.14.9,okio-1.17.5版本,如果冲突,烦请手动引入相关jar包**。完整依赖如下:
|
60 | 56 |
|
61 | 57 |
|
@@ -143,7 +139,7 @@ public class TestService {
|
143 | 139 |
|
144 | 140 | ## 配置项说明
|
145 | 141 |
|
146 |
| -`retrofit-spring-boot-starter`支持了多个可配置的属性,用来应对不同的业务场景,具体可支持的配置项及默认值如下: |
| 142 | +组件支持了多个可配置的属性,用来应对不同的业务场景,具体可支持的配置项及默认值如下: |
147 | 143 |
|
148 | 144 | **注意:应用只需要配置要更改的配置项!**
|
149 | 145 |
|
@@ -208,7 +204,7 @@ retrofit:
|
208 | 204 | ### 自定义OkHttpClient属性
|
209 | 205 |
|
210 | 206 | 通过实现`SourceOkHttpClientRegistrar`接口,可以实现自定义注册。然后使用`@RetrofitClient`的`sourceOkHttpClient`属性指定`源OkHttpClient`。
|
211 |
| -系统会基于该`OkHttpClient`创建当前接口使用的`OkHttpClient`。可以配置超时时间、代理、连接池、分发等等属性。 |
| 207 | +组件会基于该`OkHttpClient`创建当前接口使用的`OkHttpClient`。可以配置超时时间、代理、连接池、分发等等属性。 |
212 | 208 |
|
213 | 209 | ```java
|
214 | 210 |
|
@@ -240,7 +236,7 @@ public class CustomSourceOkHttpClientRegistrar implements SourceOkHttpClientRegi
|
240 | 236 |
|
241 | 237 | ### 注解式拦截器
|
242 | 238 |
|
243 |
| -很多时候,我们希望某个接口下的某些http请求执行统一的拦截处理逻辑。为了支持这个功能,`retrofit-spring-boot-starter`提供了**注解式拦截器**,做到了**基于url路径的匹配拦截**。使用的步骤主要分为2步: |
| 239 | +很多时候,我们希望某个接口下的某些http请求执行统一的拦截处理逻辑。为了支持这个功能,组件提供了**注解式拦截器**,做到了**基于url路径的匹配拦截**。使用的步骤主要分为2步: |
244 | 240 |
|
245 | 241 | 1. 继承`BasePathMatchInterceptor`编写拦截处理器;
|
246 | 242 | 2. 接口上使用`@Intercept`进行标注。如需配置多个拦截器,在接口上标注多个`@Intercept`注解即可!
|
@@ -403,7 +399,7 @@ public interface HttpApi {
|
403 | 399 |
|
404 | 400 | ### 日志打印
|
405 | 401 |
|
406 |
| -`retrofit-spring-boot-starter`支持支持全局日志打印和声明式日志打印。 |
| 402 | +组件支持支持全局日志打印和声明式日志打印。 |
407 | 403 |
|
408 | 404 | #### 全局日志打印
|
409 | 405 |
|
@@ -438,7 +434,7 @@ retrofit:
|
438 | 434 |
|
439 | 435 | ### 请求重试
|
440 | 436 |
|
441 |
| -`retrofit-spring-boot-starter`支持支持全局重试和声明式重试。 |
| 437 | +组件支持支持全局重试和声明式重试。 |
442 | 438 |
|
443 | 439 | #### 全局重试
|
444 | 440 |
|
@@ -698,7 +694,8 @@ public interface ErrorDecoder {
|
698 | 694 |
|
699 | 695 | #### 配置`ServiceInstanceChooser`为`Spring`容器`Bean`
|
700 | 696 |
|
701 |
| -用户可以自行实现`ServiceInstanceChooser`接口,完成服务实例的选取逻辑,并将其配置成`Spring`容器的`Bean`。对于`Spring Cloud`应用,`retrofit-spring-boot-starter`提供了`SpringCloudServiceInstanceChooser`实现,用户只需将其配置成`Spring`的`Bean`即可。 |
| 697 | +用户可以自行实现`ServiceInstanceChooser`接口,完成服务实例的选取逻辑,并将其配置成`Spring`容器的`Bean`。对于`Spring Cloud` |
| 698 | +应用,组件提供了`SpringCloudServiceInstanceChooser`实现,用户只需将其配置成`Spring`的`Bean`即可。 |
702 | 699 |
|
703 | 700 | ```java
|
704 | 701 | @Bean
|
@@ -755,7 +752,7 @@ public class SourceGlobalInterceptor implements GlobalInterceptor {
|
755 | 752 |
|
756 | 753 | ### 调用适配器
|
757 | 754 |
|
758 |
| -`Retrofit`可以通过调用适配器`CallAdapterFactory`将`Call<T>`对象适配成接口方法的返回值类型。`retrofit-spring-boot-starter`扩展2种`CallAdapterFactory` |
| 755 | +`Retrofit`可以通过调用适配器`CallAdapterFactory`将`Call<T>`对象适配成接口方法的返回值类型。组件扩展2种`CallAdapterFactory` |
759 | 756 | 实现:
|
760 | 757 |
|
761 | 758 | 1. `BodyCallAdapterFactory`
|
@@ -827,7 +824,8 @@ public class SourceGlobalInterceptor implements GlobalInterceptor {
|
827 | 824 |
|
828 | 825 | **我们也可以通过继承`CallAdapter.Factory`扩展实现自己的`CallAdapter`**!
|
829 | 826 |
|
830 |
| -`retrofit-spring-boot-starter`支持通过`retrofit.global-call-adapter-factories`配置全局调用适配器工厂,工厂实例优先从Spring容器获取,如果没有获取到,则反射创建。默认的全局调用适配器工厂是`[BodyCallAdapterFactory, ResponseCallAdapterFactory]`! |
| 827 | +组件支持通过`retrofit.global-call-adapter-factories` |
| 828 | +配置全局调用适配器工厂,工厂实例优先从Spring容器获取,如果没有获取到,则反射创建。默认的全局调用适配器工厂是`[BodyCallAdapterFactory, ResponseCallAdapterFactory]`! |
831 | 829 |
|
832 | 830 | ```yaml
|
833 | 831 | retrofit:
|
@@ -855,7 +853,7 @@ retrofit:
|
855 | 853 | - [JAXB](https://docs.oracle.com/javase/tutorial/jaxb/intro/index.html): com.squareup.retrofit2:converter-jaxb
|
856 | 854 | - fastJson:com.alibaba.fastjson.support.retrofit.Retrofit2ConverterFactory
|
857 | 855 |
|
858 |
| -`retrofit-spring-boot-starter`支持通过`retrofit.global-converter-factories`配置全局数据转换器工厂,转换器工厂实例优先从Spring容器获取,如果没有获取到,则反射创建。 |
| 856 | +组件支持通过`retrofit.global-converter-factories`配置全局数据转换器工厂,转换器工厂实例优先从Spring容器获取,如果没有获取到,则反射创建。 |
859 | 857 | 默认的全局数据转换器工厂是`retrofit2.converter.jackson.JacksonConverterFactory`。如果需要修改jackson配置,自行覆盖`JacksonConverterFactory`的`bean`
|
860 | 858 | 配置即可。
|
861 | 859 |
|
|
0 commit comments