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