-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`beanFactory.isTypeMatch` may lead to the initialization of FactoryBean, dubbo consumer is a ReferenceBean which implements FactoryBean. related to #2328 #3865
- Loading branch information
Showing
2 changed files
with
11 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]) | ||
|
@@ -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; | ||
} | ||
} | ||
|