Skip to content

Commit

Permalink
Add overloaded shortcut method to register BeanDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
refeccd authored and nobodyiam committed Sep 20, 2022
1 parent 78aaca1 commit 2fefcc7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,13 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B
// to make sure the default PropertySourcesPlaceholderConfigurer's priority is higher than PropertyPlaceholderConfigurer
propertySourcesPlaceholderPropertyValues.put("order", 0);

BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesPlaceholderConfigurer.class.getName(),
PropertySourcesPlaceholderConfigurer.class, propertySourcesPlaceholderPropertyValues);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry,
AutoUpdateConfigChangeListener.class.getName(), AutoUpdateConfigChangeListener.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesProcessor.class.getName(),
PropertySourcesProcessor.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, ApolloAnnotationProcessor.class.getName(),
ApolloAnnotationProcessor.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, SpringValueProcessor.class.getName(),
SpringValueProcessor.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, SpringValueDefinitionProcessor.class.getName(),
SpringValueDefinitionProcessor.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesPlaceholderConfigurer.class,
propertySourcesPlaceholderPropertyValues);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, AutoUpdateConfigChangeListener.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesProcessor.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, ApolloAnnotationProcessor.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, SpringValueProcessor.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, SpringValueDefinitionProcessor.class);
}

private String[] resolveNamespaces(String[] namespaces) {
Expand Down Expand Up @@ -102,4 +97,4 @@ public int getOrder() {
public void setEnvironment(Environment environment) {
this.environment = environment;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) t
// to make sure the default PropertySourcesPlaceholderConfigurer's priority is higher than PropertyPlaceholderConfigurer
propertySourcesPlaceholderPropertyValues.put("order", 0);

BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesPlaceholderConfigurer.class.getName(),
PropertySourcesPlaceholderConfigurer.class, propertySourcesPlaceholderPropertyValues);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry,
AutoUpdateConfigChangeListener.class.getName(), AutoUpdateConfigChangeListener.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, ApolloAnnotationProcessor.class.getName(),
ApolloAnnotationProcessor.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, SpringValueProcessor.class.getName(),
SpringValueProcessor.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesPlaceholderConfigurer.class,
propertySourcesPlaceholderPropertyValues);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, AutoUpdateConfigChangeListener.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, ApolloAnnotationProcessor.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, SpringValueProcessor.class);

processSpringValueDefinition(registry);
}
Expand All @@ -63,4 +60,4 @@ private void processSpringValueDefinition(BeanDefinitionRegistry registry) {
public int getOrder() {
return Ordered.LOWEST_PRECEDENCE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,17 @@ public class BeanRegistrationUtil {
);
}

public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry registry, Class<?> beanClass) {
return registerBeanDefinitionIfNotExists(registry, beanClass, null);
}

public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry registry, Class<?> beanClass,
Map<String, Object> extraPropertyValues) {
return registerBeanDefinitionIfNotExists(registry, beanClass.getName(), beanClass, extraPropertyValues);
}

public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry registry, String beanName,
Class<?> beanClass) {
Class<?> beanClass) {
return registerBeanDefinitionIfNotExists(registry, beanName, beanClass, null);
}

Expand Down Expand Up @@ -80,5 +89,4 @@ public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry r
return true;
}


}
}

0 comments on commit 2fefcc7

Please sign in to comment.