Skip to content

Commit

Permalink
Fix #4152 (#4161)
Browse files Browse the repository at this point in the history
* Fix #4152
`beanFactory.isTypeMatch` may lead to the initialization of FactoryBean,
dubbo consumer is a ReferenceBean which implements FactoryBean.

related to #2328 #3865

* Update CHANGES.md

Co-authored-by: Jason Song <[email protected]>
  • Loading branch information
lonre and nobodyiam authored Dec 19, 2021
1 parent fcfc429 commit 83e87ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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([email protected])
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 83e87ba

Please sign in to comment.