Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
`beanFactory.isTypeMatch` may lead to the initialization of FactoryBean,
dubbo consumer is a ReferenceBean which implements FactoryBean.
support spring 3

related to apolloconfig#2328 apolloconfig#3865 apolloconfig#4161 apolloconfig#4164
  • Loading branch information
lonre committed Dec 21, 2021
1 parent 83e87ba commit 19ee6c3
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

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;
Expand All @@ -29,6 +29,15 @@
* @author Jason Song(song_s@ctrip.com)
*/
public class BeanRegistrationUtil {
private static final Map<String, String> BD_MAPPING = new ConcurrentHashMap<>();

static {
BD_MAPPING.put(
"org.springframework.context.support.PropertySourcesPlaceholderConfigurer",
"org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer"
);
}

public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry registry, String beanName,
Class<?> beanClass) {
return registerBeanDefinitionIfNotExists(registry, beanName, beanClass, null);
Expand All @@ -48,9 +57,9 @@ public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry r
return false;
}

if (beanDefinition instanceof AnnotatedBeanDefinition) {
MethodMetadata metadata = ((AnnotatedBeanDefinition) beanDefinition).getFactoryMethodMetadata();
if (metadata != null && Objects.equals(metadata.getReturnTypeName(), beanClass.getName())) {
if (BD_MAPPING.containsKey(beanClass.getName()) && beanDefinition.getSource() != null && beanDefinition.getSource() instanceof MethodMetadata) {
MethodMetadata metadata = (MethodMetadata) beanDefinition.getSource();
if (Objects.equals(BD_MAPPING.get(beanClass.getName()), String.format("%s#%s", metadata.getDeclaringClassName(), metadata.getMethodName()))) {
return false;
}
}
Expand Down

0 comments on commit 19ee6c3

Please sign in to comment.