From 2fefcc7d480ce93e7ba8f4861184049860932fcd Mon Sep 17 00:00:00 2001 From: liaozan <378024053@qq.com> Date: Sun, 18 Sep 2022 23:10:07 +0800 Subject: [PATCH] Add overloaded shortcut method to register BeanDefinition --- .../DefaultApolloConfigRegistrarHelper.java | 21 +++++++------------ ...tConfigPropertySourcesProcessorHelper.java | 15 ++++++------- .../spring/util/BeanRegistrationUtil.java | 14 ++++++++++--- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultApolloConfigRegistrarHelper.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultApolloConfigRegistrarHelper.java index ec8af35073c..8bd2b7610ef 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultApolloConfigRegistrarHelper.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultApolloConfigRegistrarHelper.java @@ -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) { @@ -102,4 +97,4 @@ public int getOrder() { public void setEnvironment(Environment environment) { this.environment = environment; } -} +} \ No newline at end of file diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultConfigPropertySourcesProcessorHelper.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultConfigPropertySourcesProcessorHelper.java index a04f5ae7678..51dc7697cf9 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultConfigPropertySourcesProcessorHelper.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultConfigPropertySourcesProcessorHelper.java @@ -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); } @@ -63,4 +60,4 @@ private void processSpringValueDefinition(BeanDefinitionRegistry registry) { public int getOrder() { return Ordered.LOWEST_PRECEDENCE; } -} +} \ No newline at end of file diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java index 079c366b63f..46044957def 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java @@ -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 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); } @@ -80,5 +89,4 @@ public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry r return true; } - -} +} \ No newline at end of file