From 780930b372fec331eb40ed927bde7c1653b46241 Mon Sep 17 00:00:00 2001 From: wangfangyuan <201512825@qq.com> Date: Thu, 31 Mar 2022 13:07:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E5=8A=A8=E6=80=81=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E7=B1=BB=E7=9A=84=E5=B1=9E=E6=80=A7=E8=B5=8B=E5=80=BC?= =?UTF-8?q?=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spring/boot/core/RetrofitFactoryBean.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 8f693da..0255e17 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 @@ -15,6 +15,8 @@ import okhttp3.OkHttpClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.aop.framework.Advised; +import org.springframework.aop.support.AopUtils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.FactoryBean; import org.springframework.context.ApplicationContext; @@ -395,7 +397,7 @@ private List findInterceptorByAnnotation(Class retrofitClientInt private BasePathMatchInterceptor getInterceptorInstance(Class interceptorClass) throws IllegalAccessException, InstantiationException { // spring bean try { - return applicationContext.getBean(interceptorClass); + return getTargetBean(applicationContext.getBean(interceptorClass)); } catch (BeansException e) { // spring容器获取失败,反射创建 return interceptorClass.newInstance(); @@ -403,6 +405,19 @@ private BasePathMatchInterceptor getInterceptorInstance(Class T getTargetBean(Object bean) { + Object object = bean; + while (AopUtils.isAopProxy(object)) { + try { + object = ((Advised) object).getTargetSource().getTarget(); + } catch (Exception e) { + throw new RuntimeException("get target bean failed", e); + } + } + return (T) object; + } + + /** * 获取Retrofit实例,一个retrofitClient接口对应一个Retrofit实例 * Obtain a Retrofit instance, a retrofitClient interface corresponds to a Retrofit instance