Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Fix apolloconfig#2328

case: beanDefinition of the bean defined in Configuration annotated class
in this case, the `beanDefinition.getBeanClassName()` and `beanClass.getName()` is not match

* Update CHANGES.md

Co-authored-by: Jason Song <[email protected]>
  • Loading branch information
lonre and nobodyiam authored Aug 8, 2021
1 parent 9eff000 commit 8c0241c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Apollo 1.9.0
* [support json/yaml/xml format for public namespace](https://github.com/ctripcorp/apollo/pull/3836)
* [Translate application into 应用 not 项目](https://github.com/ctripcorp/apollo/pull/3877)
* [add spring configuration metadata for property names cache](https://github.com/ctripcorp/apollo/pull/3879)
* [Fix Multiple PropertySourcesPlaceholderConfigurer beans registered issue](https://github.com/ctripcorp/apollo/pull/3865)
* [use jdk 8 to publish apollo-client-config-data](https://github.com/ctripcorp/apollo/pull/3880)

------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;
import java.util.Objects;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
Expand All @@ -40,10 +41,19 @@ public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry r

String[] candidates = registry.getBeanDefinitionNames();

for (String candidate : candidates) {
BeanDefinition beanDefinition = registry.getBeanDefinition(candidate);
if (Objects.equals(beanDefinition.getBeanClassName(), beanClass.getName())) {
return false;
if (registry instanceof BeanFactory) {
final BeanFactory beanFactory = (BeanFactory) registry;
for (String candidate : candidates) {
if (beanFactory.isTypeMatch(candidate, beanClass)) {
return false;
}
}
} else {
for (String candidate : candidates) {
BeanDefinition beanDefinition = registry.getBeanDefinition(candidate);
if (Objects.equals(beanDefinition.getBeanClassName(), beanClass.getName())) {
return false;
}
}
}

Expand Down

0 comments on commit 8c0241c

Please sign in to comment.