From a5e394e25fc0f912f4089e0d2e0bf95b0a7b022e Mon Sep 17 00:00:00 2001 From: yuhuangbin Date: Fri, 3 Jan 2025 15:09:34 +0800 Subject: [PATCH 1/6] code feat: More detailed Datasouce routing support --- dynamic-datasource-spring-boot-common/pom.xml | 7 ++ .../DynamicDataSourceProperties.java | 12 ++- .../DynamicDatasourceAopProperties.java | 13 ++++ ...sourceConfigurationPropertiesReBinder.java | 36 +++++++++ .../PropertiesReBinderAutoConfiguration.java | 17 +++++ .../DynamicDataSourceAopConfiguration.java | 16 +++- .../DynamicDataSourceAutoConfiguration.java | 3 +- .../aop/DynamicDataSourceNamedAdvisor.java | 74 +++++++++++++++++++ pom.xml | 9 +++ 9 files changed, 182 insertions(+), 5 deletions(-) create mode 100644 dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDatasourceConfigurationPropertiesReBinder.java create mode 100644 dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/PropertiesReBinderAutoConfiguration.java create mode 100644 dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/aop/DynamicDataSourceNamedAdvisor.java diff --git a/dynamic-datasource-spring-boot-common/pom.xml b/dynamic-datasource-spring-boot-common/pom.xml index 817d4b7c..ac43bf1d 100644 --- a/dynamic-datasource-spring-boot-common/pom.xml +++ b/dynamic-datasource-spring-boot-common/pom.xml @@ -65,5 +65,12 @@ spring-boot-configuration-processor true + + + org.springframework.cloud + spring-cloud-context + compile + true + \ No newline at end of file diff --git a/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceProperties.java b/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceProperties.java index 0fc1f0a6..bcb0ee2f 100644 --- a/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceProperties.java +++ b/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceProperties.java @@ -29,6 +29,7 @@ import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.BeanNameAware; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; @@ -45,7 +46,7 @@ @Getter @Setter @ConfigurationProperties(prefix = DynamicDataSourceProperties.PREFIX) -public class DynamicDataSourceProperties { +public class DynamicDataSourceProperties implements BeanNameAware { public static final String PREFIX = "spring.datasource.dynamic"; @@ -81,6 +82,10 @@ public class DynamicDataSourceProperties { * 全局默认publicKey */ private String publicKey = CryptoUtils.DEFAULT_PUBLIC_KEY_STRING; + /** + * beanName + */ + private String beanName; /** * 每一个数据源 */ @@ -125,4 +130,9 @@ public class DynamicDataSourceProperties { */ @NestedConfigurationProperty private DynamicDatasourceAopProperties aop = new DynamicDatasourceAopProperties(); + + @Override + public void setBeanName(String beanName) { + this.beanName = beanName; + } } \ No newline at end of file diff --git a/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDatasourceAopProperties.java b/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDatasourceAopProperties.java index dfaac567..6b0b2a7d 100644 --- a/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDatasourceAopProperties.java +++ b/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDatasourceAopProperties.java @@ -18,6 +18,9 @@ import lombok.Data; import org.springframework.core.Ordered; +import java.util.List; +import java.util.Map; + /** * 多数据源aop相关配置 * @@ -38,4 +41,14 @@ public class DynamicDatasourceAopProperties { * aop allowedPublicOnly */ private Boolean allowedPublicOnly = true; + + /** + * aop scanPackagePatterns + */ + private List scanPackagePatterns; + + /** + * dynamic datasource routes + */ + private Map dsRoutes; } \ No newline at end of file diff --git a/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDatasourceConfigurationPropertiesReBinder.java b/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDatasourceConfigurationPropertiesReBinder.java new file mode 100644 index 00000000..9abefbb2 --- /dev/null +++ b/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDatasourceConfigurationPropertiesReBinder.java @@ -0,0 +1,36 @@ +package com.baomidou.dynamic.datasource.spring.boot.autoconfigure; + +import org.springframework.cloud.context.properties.ConfigurationPropertiesBeans; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextRefreshedEvent; + +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * A compensation mechanism used to support dynamic updates + * {@link ConfigurationPropertiesBeans } loaded after {@link DynamicDataSourceProperties} + * @see org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder + * + * @author yuhuangbin + */ +public class DynamicDatasourceConfigurationPropertiesReBinder implements ApplicationListener { + + private final AtomicBoolean started = new AtomicBoolean(false); + + private final ConfigurationPropertiesBeans configurationPropertiesBeans; + + public DynamicDatasourceConfigurationPropertiesReBinder(ConfigurationPropertiesBeans configurationPropertiesBeans) { + this.configurationPropertiesBeans = configurationPropertiesBeans; + } + + @Override + public void onApplicationEvent(ContextRefreshedEvent event) { + if (!started.compareAndSet(false, true)) { + return; + } + ApplicationContext applicationContext = event.getApplicationContext(); + DynamicDataSourceProperties aopProperties = applicationContext.getBean(DynamicDataSourceProperties.class); + configurationPropertiesBeans.postProcessBeforeInitialization(aopProperties, aopProperties.getBeanName()); + } +} diff --git a/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/PropertiesReBinderAutoConfiguration.java b/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/PropertiesReBinderAutoConfiguration.java new file mode 100644 index 00000000..11f80ea5 --- /dev/null +++ b/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/PropertiesReBinderAutoConfiguration.java @@ -0,0 +1,17 @@ +package com.baomidou.dynamic.datasource.spring.boot.autoconfigure; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration; +import org.springframework.cloud.context.properties.ConfigurationPropertiesBeans; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +@ConditionalOnClass(ConfigurationPropertiesRebinderAutoConfiguration.class) +public class PropertiesReBinderAutoConfiguration { + + @Bean + public DynamicDatasourceConfigurationPropertiesReBinder dsConfigurationReBinder(ConfigurationPropertiesBeans configurationPropertiesBeans) { + return new DynamicDatasourceConfigurationPropertiesReBinder(configurationPropertiesBeans); + } +} diff --git a/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAopConfiguration.java b/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAopConfiguration.java index 9d5f34e1..72b18e28 100644 --- a/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAopConfiguration.java +++ b/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAopConfiguration.java @@ -18,9 +18,7 @@ import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DSTransactional; -import com.baomidou.dynamic.datasource.aop.DynamicDataSourceAnnotationAdvisor; -import com.baomidou.dynamic.datasource.aop.DynamicDataSourceAnnotationInterceptor; -import com.baomidou.dynamic.datasource.aop.DynamicLocalTransactionInterceptor; +import com.baomidou.dynamic.datasource.aop.*; import com.baomidou.dynamic.datasource.processor.DsJakartaHeaderProcessor; import com.baomidou.dynamic.datasource.processor.DsJakartaSessionProcessor; import com.baomidou.dynamic.datasource.processor.DsProcessor; @@ -87,6 +85,18 @@ public Advisor dynamicDatasourceAnnotationAdvisor(DsProcessor dsProcessor) { return advisor; } + @Role(BeanDefinition.ROLE_INFRASTRUCTURE) + @Bean + @ConditionalOnProperty(prefix = DynamicDataSourceProperties.PREFIX + ".aop", name = "enabled", havingValue = "true", matchIfMissing = true) + public Advisor dynamicDataSourceNamedAdvisor(DsProcessor dsProcessor) { + DynamicDatasourceAopProperties aopProperties = properties.getAop(); + DynamicDatasourceNamedInterceptor interceptor = new DynamicDatasourceNamedInterceptor(dsProcessor); + interceptor.addPatternMap(aopProperties.getDsRoutes()); + DynamicDataSourceNamedAdvisor advisor = new DynamicDataSourceNamedAdvisor(interceptor, aopProperties.getScanPackagePatterns()); + advisor.setOrder(aopProperties.getOrder() + 1); + return advisor; + } + @Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Bean @ConditionalOnProperty(prefix = DynamicDataSourceProperties.PREFIX, name = "seata", havingValue = "false", matchIfMissing = true) diff --git a/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAutoConfiguration.java b/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAutoConfiguration.java index 385e3847..0b49ee14 100644 --- a/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAutoConfiguration.java +++ b/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAutoConfiguration.java @@ -46,7 +46,8 @@ "com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure", "com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceAutoConfigure" }) -@Import({DruidDynamicDataSourceConfiguration.class, DynamicDataSourceCreatorAutoConfiguration.class, DynamicDataSourceAopConfiguration.class, DynamicDataSourceAssistConfiguration.class}) +@Import({DruidDynamicDataSourceConfiguration.class, DynamicDataSourceCreatorAutoConfiguration.class, + DynamicDataSourceAopConfiguration.class, DynamicDataSourceAssistConfiguration.class, PropertiesReBinderAutoConfiguration.class}) @ConditionalOnProperty(prefix = DynamicDataSourceProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) public class DynamicDataSourceAutoConfiguration implements InitializingBean { diff --git a/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/aop/DynamicDataSourceNamedAdvisor.java b/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/aop/DynamicDataSourceNamedAdvisor.java new file mode 100644 index 00000000..73ebfda9 --- /dev/null +++ b/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/aop/DynamicDataSourceNamedAdvisor.java @@ -0,0 +1,74 @@ +package com.baomidou.dynamic.datasource.aop; + +import org.aopalliance.aop.Advice; +import org.springframework.aop.ClassFilter; +import org.springframework.aop.MethodMatcher; +import org.springframework.aop.Pointcut; +import org.springframework.aop.support.AbstractPointcutAdvisor; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.util.ClassUtils; +import org.springframework.util.CollectionUtils; +import org.springframework.util.PatternMatchUtils; + +import java.util.List; + +/** + * @author yuhuangbin + */ +public class DynamicDataSourceNamedAdvisor extends AbstractPointcutAdvisor implements BeanFactoryAware { + + /** + * the advice + */ + private final Advice advice; + /** + * the pointcut + */ + private final Pointcut pointcut; + + + public DynamicDataSourceNamedAdvisor(Advice advice, List scanPackages) { + this.advice = advice; + this.pointcut = new ClassPackageNamedPointCut(scanPackages); + } + + @Override + public Pointcut getPointcut() { + return pointcut; + } + + @Override + public Advice getAdvice() { + return advice; + } + + @Override + public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + if (this.advice instanceof BeanFactoryAware) { + ((BeanFactoryAware) this.advice).setBeanFactory(beanFactory); + } + } + + public static class ClassPackageNamedPointCut implements Pointcut { + + private final ClassFilter classFilter; + + public ClassPackageNamedPointCut(List packagePatterns) { + this.classFilter = clazz -> !CollectionUtils.isEmpty(packagePatterns) + && PatternMatchUtils.simpleMatch(packagePatterns.toArray(new String[0]), ClassUtils.getPackageName(clazz)); + } + + @Override + public ClassFilter getClassFilter() { + return classFilter; + } + + @Override + public MethodMatcher getMethodMatcher() { + return MethodMatcher.TRUE; + } + } + +} diff --git a/pom.xml b/pom.xml index b8e9c1f5..55612adb 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,7 @@ 1.8 2.7.18 + 2023.0.3 3.5.3.2 2.4.13 1.2.20 @@ -104,6 +105,14 @@ pom import + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud-dependencies.version} + pom + import + com.baomidou mybatis-plus From ba497464df173d715e4fd34be37ccc6e318e0c59 Mon Sep 17 00:00:00 2001 From: yuhuangbin Date: Fri, 3 Jan 2025 15:48:08 +0800 Subject: [PATCH 2/6] code fix: getQualifiedMethodName --- .../datasource/aop/DynamicDatasourceNamedInterceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/aop/DynamicDatasourceNamedInterceptor.java b/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/aop/DynamicDatasourceNamedInterceptor.java index 8570d722..fc565072 100644 --- a/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/aop/DynamicDatasourceNamedInterceptor.java +++ b/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/aop/DynamicDatasourceNamedInterceptor.java @@ -126,7 +126,7 @@ private String findDsKey(MethodInvocation invocation) { } // Look for direct name match. - String methodName = method.getName(); + String methodName = ClassUtils.getQualifiedMethodName(method); String dsKey = this.nameMap.get(methodName); if (dsKey == null) { From a90c8ccbfe8525ee5028f407669c30882834c262 Mon Sep 17 00:00:00 2001 From: yuhuangbin Date: Sat, 4 Jan 2025 09:23:57 +0800 Subject: [PATCH 3/6] code fix --- ...sourceConfigurationPropertiesReBinder.java | 36 ------------------- .../PropertiesReBinderAutoConfiguration.java | 17 --------- .../DynamicDataSourceAutoConfiguration.java | 2 +- 3 files changed, 1 insertion(+), 54 deletions(-) delete mode 100644 dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDatasourceConfigurationPropertiesReBinder.java delete mode 100644 dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/PropertiesReBinderAutoConfiguration.java diff --git a/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDatasourceConfigurationPropertiesReBinder.java b/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDatasourceConfigurationPropertiesReBinder.java deleted file mode 100644 index 9abefbb2..00000000 --- a/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDatasourceConfigurationPropertiesReBinder.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.baomidou.dynamic.datasource.spring.boot.autoconfigure; - -import org.springframework.cloud.context.properties.ConfigurationPropertiesBeans; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationListener; -import org.springframework.context.event.ContextRefreshedEvent; - -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * A compensation mechanism used to support dynamic updates - * {@link ConfigurationPropertiesBeans } loaded after {@link DynamicDataSourceProperties} - * @see org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder - * - * @author yuhuangbin - */ -public class DynamicDatasourceConfigurationPropertiesReBinder implements ApplicationListener { - - private final AtomicBoolean started = new AtomicBoolean(false); - - private final ConfigurationPropertiesBeans configurationPropertiesBeans; - - public DynamicDatasourceConfigurationPropertiesReBinder(ConfigurationPropertiesBeans configurationPropertiesBeans) { - this.configurationPropertiesBeans = configurationPropertiesBeans; - } - - @Override - public void onApplicationEvent(ContextRefreshedEvent event) { - if (!started.compareAndSet(false, true)) { - return; - } - ApplicationContext applicationContext = event.getApplicationContext(); - DynamicDataSourceProperties aopProperties = applicationContext.getBean(DynamicDataSourceProperties.class); - configurationPropertiesBeans.postProcessBeforeInitialization(aopProperties, aopProperties.getBeanName()); - } -} diff --git a/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/PropertiesReBinderAutoConfiguration.java b/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/PropertiesReBinderAutoConfiguration.java deleted file mode 100644 index 11f80ea5..00000000 --- a/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/PropertiesReBinderAutoConfiguration.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baomidou.dynamic.datasource.spring.boot.autoconfigure; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration; -import org.springframework.cloud.context.properties.ConfigurationPropertiesBeans; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration(proxyBeanMethods = false) -@ConditionalOnClass(ConfigurationPropertiesRebinderAutoConfiguration.class) -public class PropertiesReBinderAutoConfiguration { - - @Bean - public DynamicDatasourceConfigurationPropertiesReBinder dsConfigurationReBinder(ConfigurationPropertiesBeans configurationPropertiesBeans) { - return new DynamicDatasourceConfigurationPropertiesReBinder(configurationPropertiesBeans); - } -} diff --git a/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAutoConfiguration.java b/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAutoConfiguration.java index 0b49ee14..0bc0107f 100644 --- a/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAutoConfiguration.java +++ b/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAutoConfiguration.java @@ -47,7 +47,7 @@ "com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceAutoConfigure" }) @Import({DruidDynamicDataSourceConfiguration.class, DynamicDataSourceCreatorAutoConfiguration.class, - DynamicDataSourceAopConfiguration.class, DynamicDataSourceAssistConfiguration.class, PropertiesReBinderAutoConfiguration.class}) + DynamicDataSourceAopConfiguration.class, DynamicDataSourceAssistConfiguration.class}) @ConditionalOnProperty(prefix = DynamicDataSourceProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) public class DynamicDataSourceAutoConfiguration implements InitializingBean { From 38b6a6cc1033fe3ff4c92e48e264ad4858b717e3 Mon Sep 17 00:00:00 2001 From: yuhuangbin Date: Sat, 4 Jan 2025 09:29:31 +0800 Subject: [PATCH 4/6] code fix --- dynamic-datasource-spring-boot-common/pom.xml | 7 ------- .../autoconfigure/DynamicDataSourceAopConfiguration.java | 2 +- ...eptor.java => DynamicDataSourceNamedInterceptor.java} | 4 ++-- pom.xml | 9 --------- 4 files changed, 3 insertions(+), 19 deletions(-) rename dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/aop/{DynamicDatasourceNamedInterceptor.java => DynamicDataSourceNamedInterceptor.java} (97%) diff --git a/dynamic-datasource-spring-boot-common/pom.xml b/dynamic-datasource-spring-boot-common/pom.xml index ac43bf1d..817d4b7c 100644 --- a/dynamic-datasource-spring-boot-common/pom.xml +++ b/dynamic-datasource-spring-boot-common/pom.xml @@ -65,12 +65,5 @@ spring-boot-configuration-processor true - - - org.springframework.cloud - spring-cloud-context - compile - true - \ No newline at end of file diff --git a/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAopConfiguration.java b/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAopConfiguration.java index 72b18e28..cad5f5fb 100644 --- a/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAopConfiguration.java +++ b/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAopConfiguration.java @@ -90,7 +90,7 @@ public Advisor dynamicDatasourceAnnotationAdvisor(DsProcessor dsProcessor) { @ConditionalOnProperty(prefix = DynamicDataSourceProperties.PREFIX + ".aop", name = "enabled", havingValue = "true", matchIfMissing = true) public Advisor dynamicDataSourceNamedAdvisor(DsProcessor dsProcessor) { DynamicDatasourceAopProperties aopProperties = properties.getAop(); - DynamicDatasourceNamedInterceptor interceptor = new DynamicDatasourceNamedInterceptor(dsProcessor); + DynamicDataSourceNamedInterceptor interceptor = new DynamicDataSourceNamedInterceptor(dsProcessor); interceptor.addPatternMap(aopProperties.getDsRoutes()); DynamicDataSourceNamedAdvisor advisor = new DynamicDataSourceNamedAdvisor(interceptor, aopProperties.getScanPackagePatterns()); advisor.setOrder(aopProperties.getOrder() + 1); diff --git a/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/aop/DynamicDatasourceNamedInterceptor.java b/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/aop/DynamicDataSourceNamedInterceptor.java similarity index 97% rename from dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/aop/DynamicDatasourceNamedInterceptor.java rename to dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/aop/DynamicDataSourceNamedInterceptor.java index fc565072..e1e8ac32 100644 --- a/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/aop/DynamicDatasourceNamedInterceptor.java +++ b/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/aop/DynamicDataSourceNamedInterceptor.java @@ -39,7 +39,7 @@ * @since 3.4.0 */ @Slf4j -public class DynamicDatasourceNamedInterceptor implements MethodInterceptor { +public class DynamicDataSourceNamedInterceptor implements MethodInterceptor { private static final String DYNAMIC_PREFIX = "#"; private final Map nameMap = new HashMap<>(); @@ -50,7 +50,7 @@ public class DynamicDatasourceNamedInterceptor implements MethodInterceptor { * * @param dsProcessor dsProcessor */ - public DynamicDatasourceNamedInterceptor(DsProcessor dsProcessor) { + public DynamicDataSourceNamedInterceptor(DsProcessor dsProcessor) { this.dsProcessor = dsProcessor; } diff --git a/pom.xml b/pom.xml index 55612adb..b8e9c1f5 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,6 @@ 1.8 2.7.18 - 2023.0.3 3.5.3.2 2.4.13 1.2.20 @@ -105,14 +104,6 @@ pom import - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud-dependencies.version} - pom - import - com.baomidou mybatis-plus From 13faa1f658a2370eb2cef1fe2e77ff437bb1e373 Mon Sep 17 00:00:00 2001 From: yuhuangbin Date: Sat, 4 Jan 2025 09:49:29 +0800 Subject: [PATCH 5/6] code fix --- .../boot/autoconfigure/DynamicDataSourceProperties.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceProperties.java b/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceProperties.java index bcb0ee2f..dc3e1462 100644 --- a/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceProperties.java +++ b/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceProperties.java @@ -29,7 +29,6 @@ import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.BeanNameAware; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; @@ -46,7 +45,7 @@ @Getter @Setter @ConfigurationProperties(prefix = DynamicDataSourceProperties.PREFIX) -public class DynamicDataSourceProperties implements BeanNameAware { +public class DynamicDataSourceProperties { public static final String PREFIX = "spring.datasource.dynamic"; @@ -131,8 +130,4 @@ public class DynamicDataSourceProperties implements BeanNameAware { @NestedConfigurationProperty private DynamicDatasourceAopProperties aop = new DynamicDatasourceAopProperties(); - @Override - public void setBeanName(String beanName) { - this.beanName = beanName; - } } \ No newline at end of file From b65dae29dd953964a6c6fbd32d34243ac58cbebf Mon Sep 17 00:00:00 2001 From: yuhuangbin Date: Sat, 4 Jan 2025 10:22:15 +0800 Subject: [PATCH 6/6] code fix --- .../boot/autoconfigure/DynamicDataSourceProperties.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceProperties.java b/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceProperties.java index dc3e1462..1c9fb568 100644 --- a/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceProperties.java +++ b/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceProperties.java @@ -81,10 +81,6 @@ public class DynamicDataSourceProperties { * 全局默认publicKey */ private String publicKey = CryptoUtils.DEFAULT_PUBLIC_KEY_STRING; - /** - * beanName - */ - private String beanName; /** * 每一个数据源 */