Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
chentianming11 committed Mar 31, 2022
2 parents f119d4c + a9a1836 commit f01a06b
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

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;
Expand Down Expand Up @@ -407,13 +409,15 @@ private List<Interceptor> 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.
Expand All @@ -431,6 +435,18 @@ private BasePathMatchInterceptor getInterceptorInstance(Class<? extends BasePath
}
}

private static <T> T getTargetBean(T bean) {
Object object = bean;
if (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实例
Expand Down

0 comments on commit f01a06b

Please sign in to comment.