From a7c7a943834e9c0df901a826f356d3165e9aeaaa Mon Sep 17 00:00:00 2001 From: chentianming Date: Sat, 30 Apr 2022 13:07:17 +0800 Subject: [PATCH] fix BaseLoggingInterceptor --- README.md | 28 ++++---- .../spring/boot/core/RetrofitFactoryBean.java | 2 +- .../interceptor/BaseLoggingInterceptor.java | 4 +- src/test/resources/default-config.yml | 66 +++++++++++++++++++ 4 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 src/test/resources/default-config.yml diff --git a/README.md b/README.md index 0799978..2440c35 100644 --- a/README.md +++ b/README.md @@ -147,18 +147,20 @@ public class TestService { ## 配置项说明 -`retrofit-spring-boot-starter`支持了多个可配置的属性,用来应对不同的业务场景。** +`retrofit-spring-boot-starter`支持了多个可配置的属性,用来应对不同的业务场景,具体可支持的配置项及默认值如下: + +**注意:应用只需要配置要更改的配置项即可!** ```yaml retrofit: # 连接池配置 pool: - # test1连接池配置 - test1: + # default连接池 + default: # 最大空闲连接数 - max-idle-connections: 3 + max-idle-connections: 5 # 连接保活时间(秒) - keep-alive-second: 100 + keep-alive-second: 300 # 是否禁用void返回值类型 disable-void-return-type: false @@ -182,17 +184,17 @@ retrofit: # 全局日志打印级别 global-log-level: info # 全局日志打印策略 - global-log-strategy: body + global-log-strategy: basic # 重试配置 retry: # 是否启用全局重试 - enable-global-retry: true + enable-global-retry: false # 全局重试间隔时间 - global-interval-ms: 1 + global-interval-ms: 100 # 全局最大重试次数 - global-max-retries: 1 + global-max-retries: 2 # 全局重试规则 global-retry-rules: - response_status_not_2xx @@ -203,17 +205,17 @@ retrofit: # 熔断降级配置 degrade: # 是否启用熔断降级 - enable: true + enable: false # 熔断降级实现方式 degrade-type: sentinel # 熔断资源名称解析器 resource-name-parser: com.github.lianjiatech.retrofit.spring.boot.degrade.DefaultResourceNameParser # 全局连接超时时间 - global-connect-timeout-ms: 5000 + global-connect-timeout-ms: 10000 # 全局读取超时时间 - global-read-timeout-ms: 5000 + global-read-timeout-ms: 10000 # 全局写入超时时间 - global-write-timeout-ms: 5000 + global-write-timeout-ms: 10000 # 全局完整调用超时时间 global-call-timeout-ms: 0 ``` diff --git a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/RetrofitFactoryBean.java b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/RetrofitFactoryBean.java index f422304..422c697 100644 --- a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/RetrofitFactoryBean.java +++ b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/RetrofitFactoryBean.java @@ -360,7 +360,7 @@ private synchronized OkHttpClient getOkHttpClient(Class retrofitClientInterfa "logStrategy cannot all be configured as LogStrategy.NULL!"); BaseLoggingInterceptor loggingInterceptor = constructor.newInstance(logLevel, logStrategy); - okHttpClientBuilder.addNetworkInterceptor(loggingInterceptor); + okHttpClientBuilder.addInterceptor(loggingInterceptor); } List networkInterceptors = retrofitConfigBean.getNetworkInterceptors(); diff --git a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/interceptor/BaseLoggingInterceptor.java b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/interceptor/BaseLoggingInterceptor.java index 6b0c524..6781d62 100644 --- a/src/main/java/com/github/lianjiatech/retrofit/spring/boot/interceptor/BaseLoggingInterceptor.java +++ b/src/main/java/com/github/lianjiatech/retrofit/spring/boot/interceptor/BaseLoggingInterceptor.java @@ -1,9 +1,11 @@ package com.github.lianjiatech.retrofit.spring.boot.interceptor; +import okhttp3.Interceptor; + /** * @author 陈添明 */ -public abstract class BaseLoggingInterceptor implements NetworkInterceptor { +public abstract class BaseLoggingInterceptor implements Interceptor { /** * 日志打印级别 diff --git a/src/test/resources/default-config.yml b/src/test/resources/default-config.yml new file mode 100644 index 0000000..6788d84 --- /dev/null +++ b/src/test/resources/default-config.yml @@ -0,0 +1,66 @@ +retrofit: + # 连接池配置 + pool: + # default连接池 + default: + # 最大空闲连接数 + max-idle-connections: 5 + # 连接保活时间(秒) + keep-alive-second: 300 + + # 是否禁用void返回值类型 + disable-void-return-type: false + + + # 全局转换器工厂 + global-converter-factories: + - com.github.lianjiatech.retrofit.spring.boot.core.BasicTypeConverterFactory + - retrofit2.converter.jackson.JacksonConverterFactory + # 全局调用适配器工厂 + global-call-adapter-factories: + - com.github.lianjiatech.retrofit.spring.boot.core.BodyCallAdapterFactory + - com.github.lianjiatech.retrofit.spring.boot.core.ResponseCallAdapterFactory + + # 日志打印配置 + log: + # 启用日志打印 + enable: true + # 日志打印拦截器 + logging-interceptor: com.github.lianjiatech.retrofit.spring.boot.interceptor.DefaultLoggingInterceptor + # 全局日志打印级别 + global-log-level: info + # 全局日志打印策略 + global-log-strategy: basic + + + # 重试配置 + retry: + # 是否启用全局重试 + enable-global-retry: false + # 全局重试间隔时间 + global-interval-ms: 100 + # 全局最大重试次数 + global-max-retries: 2 + # 全局重试规则 + global-retry-rules: + - response_status_not_2xx + - occur_io_exception + # 重试拦截器 + retry-interceptor: com.github.lianjiatech.retrofit.spring.boot.retry.DefaultRetryInterceptor + + # 熔断降级配置 + degrade: + # 是否启用熔断降级 + enable: false + # 熔断降级实现方式 + degrade-type: sentinel + # 熔断资源名称解析器 + resource-name-parser: com.github.lianjiatech.retrofit.spring.boot.degrade.DefaultResourceNameParser + # 全局连接超时时间 + global-connect-timeout-ms: 10000 + # 全局读取超时时间 + global-read-timeout-ms: 10000 + # 全局写入超时时间 + global-write-timeout-ms: 10000 + # 全局完整调用超时时间 + global-call-timeout-ms: 0