From 5421e7ce87ce4775dff2cecfdb4ab2ae319bb680 Mon Sep 17 00:00:00 2001 From: wangfangyuan <201512825@qq.com> Date: Thu, 31 Mar 2022 13:51:37 +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 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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 0255e17..8843d26 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 @@ -380,13 +380,15 @@ private List findInterceptorByAnnotation(Class retrofitClientInt annotationResolveAttributes.put(key, value); } }); + BasePathMatchInterceptor targetInterceptor = getTargetBean(interceptor); // 动态设置属性值。Set property value dynamically - BeanExtendUtils.populate(interceptor, annotationResolveAttributes); - interceptors.add(interceptor); + BeanExtendUtils.populate(targetInterceptor, annotationResolveAttributes); + interceptors.add(targetInterceptor); } return interceptors; } + /** * 获取路径拦截器实例,优先从spring容器中取。如果spring容器中不存在,则无参构造器实例化一个。 * Obtain the path interceptor instance, first from the spring container. If it does not exist in the spring container, the no-argument constructor will instantiate one. @@ -397,17 +399,16 @@ private List findInterceptorByAnnotation(Class retrofitClientInt private BasePathMatchInterceptor getInterceptorInstance(Class interceptorClass) throws IllegalAccessException, InstantiationException { // spring bean try { - return getTargetBean(applicationContext.getBean(interceptorClass)); + return applicationContext.getBean(interceptorClass); } catch (BeansException e) { // spring容器获取失败,反射创建 return interceptorClass.newInstance(); } } - - private T getTargetBean(Object bean) { + private static T getTargetBean(T bean) { Object object = bean; - while (AopUtils.isAopProxy(object)) { + if (AopUtils.isAopProxy(object)) { try { object = ((Advised) object).getTargetSource().getTarget(); } catch (Exception e) {