Skip to content

Commit 1c06030

Browse files
committed
Fix #4152
`beanFactory.isTypeMatch` may lead to the initialization of FactoryBean, dubbo consumer is a ReferenceBean which implements FactoryBean. related to #2328 #3865
1 parent fcfc429 commit 1c06030

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Release Notes.
55
Apollo 1.9.2
66

77
------------------
8+
* [Fix #4152](https://github.com/apolloconfig/apollo/pull/4161)
89

910
------------------
1011
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/10?closed=1)

apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
import java.util.Map;
2020
import java.util.Objects;
2121

22-
import org.springframework.beans.factory.BeanFactory;
22+
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
2323
import org.springframework.beans.factory.config.BeanDefinition;
2424
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
2525
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
26+
import org.springframework.core.type.MethodMetadata;
2627

2728
/**
2829
* @author Jason Song(song_s@ctrip.com)
@@ -41,17 +42,15 @@ public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry r
4142

4243
String[] candidates = registry.getBeanDefinitionNames();
4344

44-
if (registry instanceof BeanFactory) {
45-
final BeanFactory beanFactory = (BeanFactory) registry;
46-
for (String candidate : candidates) {
47-
if (beanFactory.isTypeMatch(candidate, beanClass)) {
48-
return false;
49-
}
45+
for (String candidate : candidates) {
46+
BeanDefinition beanDefinition = registry.getBeanDefinition(candidate);
47+
if (Objects.equals(beanDefinition.getBeanClassName(), beanClass.getName())) {
48+
return false;
5049
}
51-
} else {
52-
for (String candidate : candidates) {
53-
BeanDefinition beanDefinition = registry.getBeanDefinition(candidate);
54-
if (Objects.equals(beanDefinition.getBeanClassName(), beanClass.getName())) {
50+
51+
if (beanDefinition instanceof AnnotatedBeanDefinition) {
52+
MethodMetadata metadata = ((AnnotatedBeanDefinition) beanDefinition).getFactoryMethodMetadata();
53+
if (metadata != null && Objects.equals(metadata.getReturnTypeName(), beanClass.getName())) {
5554
return false;
5655
}
5756
}

0 commit comments

Comments
 (0)