diff --git a/CHANGES.md b/CHANGES.md index f4880aff50d..f6db913d6ce 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ Release Notes. Apollo 1.9.2 ------------------ +* [Fix the issue that property placeholder doesn't work for dubbo reference beans](https://github.com/apolloconfig/apollo/pull/4161) ------------------ All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/10?closed=1) diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java index 27b0cf5976d..c1fa18efbbf 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java @@ -19,10 +19,11 @@ import java.util.Map; import java.util.Objects; -import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.core.type.MethodMetadata; /** * @author Jason Song(song_s@ctrip.com) @@ -41,17 +42,15 @@ public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry r String[] candidates = registry.getBeanDefinitionNames(); - if (registry instanceof BeanFactory) { - final BeanFactory beanFactory = (BeanFactory) registry; - for (String candidate : candidates) { - if (beanFactory.isTypeMatch(candidate, beanClass)) { - return false; - } + for (String candidate : candidates) { + BeanDefinition beanDefinition = registry.getBeanDefinition(candidate); + if (Objects.equals(beanDefinition.getBeanClassName(), beanClass.getName())) { + return false; } - } else { - for (String candidate : candidates) { - BeanDefinition beanDefinition = registry.getBeanDefinition(candidate); - if (Objects.equals(beanDefinition.getBeanClassName(), beanClass.getName())) { + + if (beanDefinition instanceof AnnotatedBeanDefinition) { + MethodMetadata metadata = ((AnnotatedBeanDefinition) beanDefinition).getFactoryMethodMetadata(); + if (metadata != null && Objects.equals(metadata.getReturnTypeName(), beanClass.getName())) { return false; } }