From 7df7bd774fe4b12e56a66e1215a3d3ec610de73b Mon Sep 17 00:00:00 2001 From: hailang Date: Sat, 3 Sep 2022 12:53:08 +0800 Subject: [PATCH] [ISSUE #198] support spring @AliasFor extend --- .../java/com/qq/tars/server/apps/SpringBootAppContext.java | 4 ++-- .../qq/tars/spring/bean/CommunicatorBeanPostProcessor.java | 4 ++-- .../main/java/com/qq/tars/server/apps/TarsStartLifecycle.java | 3 ++- .../com/qq/tars/spring/bean/TarsClientBeanPostProcessor.java | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/spring/tars-spring-boot-starter/src/main/java/com/qq/tars/server/apps/SpringBootAppContext.java b/spring/tars-spring-boot-starter/src/main/java/com/qq/tars/server/apps/SpringBootAppContext.java index f7d671d3..c4834a70 100644 --- a/spring/tars-spring-boot-starter/src/main/java/com/qq/tars/server/apps/SpringBootAppContext.java +++ b/spring/tars-spring-boot-starter/src/main/java/com/qq/tars/server/apps/SpringBootAppContext.java @@ -31,7 +31,7 @@ import com.qq.tars.spring.annotation.TarsServant; import org.springframework.aop.framework.Advised; import org.springframework.context.ApplicationContext; -import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.core.annotation.AnnotatedElementUtils; import java.util.Map; @@ -93,7 +93,7 @@ private ServantHomeSkeleton loadServant(Object bean) throws Exception { ServerConfig serverCfg = ConfigurationManager.getInstance().getServerConfig(); - homeName = AnnotationUtils.getAnnotation(bean.getClass(), TarsServant.class).name(); + homeName = AnnotatedElementUtils.findMergedAnnotation(bean.getClass(), TarsServant.class).name(); if (StringUtils.isEmpty(homeName)) { throw new RuntimeException("servant name is null."); } diff --git a/spring/tars-spring-boot-starter/src/main/java/com/qq/tars/spring/bean/CommunicatorBeanPostProcessor.java b/spring/tars-spring-boot-starter/src/main/java/com/qq/tars/spring/bean/CommunicatorBeanPostProcessor.java index 6c468aac..0e9b840b 100644 --- a/spring/tars-spring-boot-starter/src/main/java/com/qq/tars/spring/bean/CommunicatorBeanPostProcessor.java +++ b/spring/tars-spring-boot-starter/src/main/java/com/qq/tars/spring/bean/CommunicatorBeanPostProcessor.java @@ -25,7 +25,7 @@ import com.qq.tars.spring.annotation.TarsClient; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.util.ReflectionUtils; import java.lang.reflect.Field; @@ -51,7 +51,7 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw private void processFields(Object bean, Field[] declaredFields) { for (Field field : declaredFields) { - TarsClient annotation = AnnotationUtils.getAnnotation(field, TarsClient.class); + TarsClient annotation = AnnotatedElementUtils.findMergedAnnotation(field, TarsClient.class); if (annotation == null) { continue; } diff --git a/spring/tars-spring-cloud-starter/src/main/java/com/qq/tars/server/apps/TarsStartLifecycle.java b/spring/tars-spring-cloud-starter/src/main/java/com/qq/tars/server/apps/TarsStartLifecycle.java index fe947f6c..d8027829 100644 --- a/spring/tars-spring-cloud-starter/src/main/java/com/qq/tars/server/apps/TarsStartLifecycle.java +++ b/spring/tars-spring-cloud-starter/src/main/java/com/qq/tars/server/apps/TarsStartLifecycle.java @@ -36,6 +36,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.SmartLifecycle; +import org.springframework.core.annotation.AnnotatedElementUtils; import java.io.IOException; import java.util.LinkedHashMap; @@ -152,7 +153,7 @@ private ServantHomeSkeleton loadServant(Object bean) throws Exception { ServerConfig serverCfg = ConfigurationManager.getInstance().getServerConfig(); - homeName = bean.getClass().getAnnotation(TarsServant.class).name(); + homeName = AnnotatedElementUtils.findMergedAnnotation(bean.getClass(), TarsServant.class).name(); if (StringUtils.isEmpty(homeName)) { throw new RuntimeException("servant name is null."); } diff --git a/spring/tars-spring-cloud-starter/src/main/java/com/qq/tars/spring/bean/TarsClientBeanPostProcessor.java b/spring/tars-spring-cloud-starter/src/main/java/com/qq/tars/spring/bean/TarsClientBeanPostProcessor.java index d7430f27..8f1f785c 100644 --- a/spring/tars-spring-cloud-starter/src/main/java/com/qq/tars/spring/bean/TarsClientBeanPostProcessor.java +++ b/spring/tars-spring-cloud-starter/src/main/java/com/qq/tars/spring/bean/TarsClientBeanPostProcessor.java @@ -34,7 +34,7 @@ import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.util.ReflectionUtils; import java.lang.reflect.Field; @@ -75,7 +75,7 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw private void processFields(Object bean, Field[] declaredFields) { for (Field field : declaredFields) { - TarsClient annotation = AnnotationUtils.getAnnotation(field, TarsClient.class); + TarsClient annotation = AnnotatedElementUtils.findMergedAnnotation(field, TarsClient.class); if (annotation == null) { continue; }