From 310b5b00a7c382778804c56b40707539e3925837 Mon Sep 17 00:00:00 2001 From: airhead Date: Tue, 23 Aug 2022 16:56:51 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat(redis):=20=E6=B3=A8=E8=A7=A3=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=A4=9A=E7=A7=9F=E6=88=B7=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.增加多租户Cache 2.修复Mac M1启动报错 --- yudao-dependencies/pom.xml | 7 +++++ .../config/YudaoTenantAutoConfiguration.java | 19 ++++++++++++ .../core/redis/TenantRedisCacheManager.java | 29 +++++++++++++++++++ .../yudao-spring-boot-starter-redis/pom.xml | 6 ++++ .../config/YudaoCacheAutoConfiguration.java | 2 ++ 5 files changed, 63 insertions(+) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index 44d7bdf68..b681f2661 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -57,6 +57,7 @@ 3.8.0 0.1.55 2.4.1 + 4.1.75.Final 8.2.2 4.5.25 @@ -509,6 +510,12 @@ ${jsch.version} + + io.netty + netty-all + ${netty-all.version} + + cn.iocoder.boot diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java index c1c969439..7896a3ad1 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java @@ -9,6 +9,7 @@ import cn.iocoder.yudao.framework.tenant.core.db.TenantDatabaseInterceptor; import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; import cn.iocoder.yudao.framework.tenant.core.job.TenantJobHandlerDecorator; import cn.iocoder.yudao.framework.tenant.core.mq.TenantRedisMessageInterceptor; +import cn.iocoder.yudao.framework.tenant.core.redis.TenantRedisCacheManager; import cn.iocoder.yudao.framework.tenant.core.security.TenantSecurityWebFilter; import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkService; import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkServiceImpl; @@ -25,6 +26,13 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.data.redis.cache.RedisCacheConfiguration; +import org.springframework.data.redis.cache.RedisCacheManager; +import org.springframework.data.redis.cache.RedisCacheWriter; +import org.springframework.data.redis.core.RedisTemplate; + +import java.util.Objects; @Configuration @ConditionalOnProperty(prefix = "yudao.tenant", value = "enable", matchIfMissing = true) // 允许使用 yudao.tenant.enable=false 禁用多租户 @@ -110,4 +118,15 @@ public class YudaoTenantAutoConfiguration { }; } + @Bean + @Primary + public RedisCacheManager tenantRedisCacheManager( + RedisTemplate redisTemplate, + RedisCacheConfiguration redisCacheConfiguration) { + RedisCacheWriter cacheWriter = + RedisCacheWriter.nonLockingRedisCacheWriter( + Objects.requireNonNull(redisTemplate.getConnectionFactory())); + return new TenantRedisCacheManager(cacheWriter, redisCacheConfiguration); + } + } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java new file mode 100644 index 000000000..ab191f0d4 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.framework.tenant.core.redis; + +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cache.Cache; +import org.springframework.data.redis.cache.RedisCacheConfiguration; +import org.springframework.data.redis.cache.RedisCacheManager; +import org.springframework.data.redis.cache.RedisCacheWriter; + +/** + * @author airhead + */ +@Slf4j +public class TenantRedisCacheManager extends RedisCacheManager { + public TenantRedisCacheManager( + RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) { + super(cacheWriter, defaultCacheConfiguration); + } + + @Override + public Cache getCache(String name) { + if (TenantContextHolder.getTenantId() == null) { + return super.getCache(name); + } + + name = name + ":" + TenantContextHolder.getTenantId(); + return super.getCache(name); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-redis/pom.xml b/yudao-framework/yudao-spring-boot-starter-redis/pom.xml index 750cd4881..5c14c02fd 100644 --- a/yudao-framework/yudao-spring-boot-starter-redis/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-redis/pom.xml @@ -32,6 +32,12 @@ spring-boot-starter-cache + + io.netty + netty-all + 4.1.75.Final + + diff --git a/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheAutoConfiguration.java index e8c716203..6a8f92efc 100644 --- a/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheAutoConfiguration.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.framework.redis.config; import org.springframework.boot.autoconfigure.cache.CacheProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -13,6 +14,7 @@ import org.springframework.data.redis.serializer.RedisSerializer; * Cache 配置类,基于 Redis 实现 */ @Configuration +@EnableConfigurationProperties({CacheProperties.class}) @EnableCaching public class YudaoCacheAutoConfiguration { From 8527bd3c77eed465304fd19238cb662e44dccefa Mon Sep 17 00:00:00 2001 From: airhead Date: Thu, 25 Aug 2022 15:53:01 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fix(tenant):=20=E7=A7=9F=E6=88=B7=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/YudaoTenantAutoConfiguration.java | 17 ++++++++++++----- .../core/redis/TenantRedisCacheManager.java | 6 ++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java index 7896a3ad1..8911f49d5 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java @@ -118,11 +118,18 @@ public class YudaoTenantAutoConfiguration { }; } - @Bean - @Primary - public RedisCacheManager tenantRedisCacheManager( - RedisTemplate redisTemplate, - RedisCacheConfiguration redisCacheConfiguration) { + /** + * 引入租户时,tenantRedisCacheManager为主Bean + * + * @param redisTemplate + * @param redisCacheConfiguration + * @return + */ + @Bean + @Primary + public RedisCacheManager tenantRedisCacheManager( + RedisTemplate redisTemplate, + RedisCacheConfiguration redisCacheConfiguration) { RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter( Objects.requireNonNull(redisTemplate.getConnectionFactory())); diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java index ab191f0d4..fa5adfa4d 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java @@ -8,10 +8,15 @@ import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.cache.RedisCacheWriter; /** + * 租户缓存管理 + * + * 为cacheName增加自动增加租户表示,格式:name+":"+tenantId + * * @author airhead */ @Slf4j public class TenantRedisCacheManager extends RedisCacheManager { + public TenantRedisCacheManager( RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) { super(cacheWriter, defaultCacheConfiguration); @@ -19,6 +24,7 @@ public class TenantRedisCacheManager extends RedisCacheManager { @Override public Cache getCache(String name) { + //租户未设置时,返回原始name if (TenantContextHolder.getTenantId() == null) { return super.getCache(name); } From 0e1babd7f41e87ecabab71524504be6466c42b78 Mon Sep 17 00:00:00 2001 From: airhead Date: Tue, 23 Aug 2022 16:56:51 +0800 Subject: [PATCH 3/6] =?UTF-8?q?feat(redis):=20=E6=B3=A8=E8=A7=A3=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=A4=9A=E7=A7=9F=E6=88=B7=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.增加多租户Cache 2.修复Mac M1启动报错 --- yudao-dependencies/pom.xml | 18 +++++------- .../config/YudaoTenantAutoConfiguration.java | 19 ++++++++++++ .../core/redis/TenantRedisCacheManager.java | 29 +++++++++++++++++++ .../yudao-spring-boot-starter-redis/pom.xml | 6 ++++ .../config/YudaoCacheAutoConfiguration.java | 2 ++ 5 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index d7912ba69..d918cb654 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -58,6 +58,7 @@ 0.1.55 2.4.1 1.3.0 + 4.1.75.Final 8.2.2 4.6.0 @@ -131,11 +132,6 @@ yudao-spring-boot-starter-biz-error-code ${revision} - - cn.iocoder.boot - yudao-spring-boot-starter-captcha - ${revision} - @@ -458,12 +454,6 @@ ${tika-core.version} - - com.anji-plus - spring-boot-starter-captcha - ${aj-captcha.version} - - org.apache.velocity velocity-engine-core @@ -521,6 +511,12 @@ ${jsch.version} + + io.netty + netty-all + ${netty-all.version} + + cn.iocoder.boot diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java index c1c969439..7896a3ad1 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java @@ -9,6 +9,7 @@ import cn.iocoder.yudao.framework.tenant.core.db.TenantDatabaseInterceptor; import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; import cn.iocoder.yudao.framework.tenant.core.job.TenantJobHandlerDecorator; import cn.iocoder.yudao.framework.tenant.core.mq.TenantRedisMessageInterceptor; +import cn.iocoder.yudao.framework.tenant.core.redis.TenantRedisCacheManager; import cn.iocoder.yudao.framework.tenant.core.security.TenantSecurityWebFilter; import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkService; import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkServiceImpl; @@ -25,6 +26,13 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.data.redis.cache.RedisCacheConfiguration; +import org.springframework.data.redis.cache.RedisCacheManager; +import org.springframework.data.redis.cache.RedisCacheWriter; +import org.springframework.data.redis.core.RedisTemplate; + +import java.util.Objects; @Configuration @ConditionalOnProperty(prefix = "yudao.tenant", value = "enable", matchIfMissing = true) // 允许使用 yudao.tenant.enable=false 禁用多租户 @@ -110,4 +118,15 @@ public class YudaoTenantAutoConfiguration { }; } + @Bean + @Primary + public RedisCacheManager tenantRedisCacheManager( + RedisTemplate redisTemplate, + RedisCacheConfiguration redisCacheConfiguration) { + RedisCacheWriter cacheWriter = + RedisCacheWriter.nonLockingRedisCacheWriter( + Objects.requireNonNull(redisTemplate.getConnectionFactory())); + return new TenantRedisCacheManager(cacheWriter, redisCacheConfiguration); + } + } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java new file mode 100644 index 000000000..ab191f0d4 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.framework.tenant.core.redis; + +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cache.Cache; +import org.springframework.data.redis.cache.RedisCacheConfiguration; +import org.springframework.data.redis.cache.RedisCacheManager; +import org.springframework.data.redis.cache.RedisCacheWriter; + +/** + * @author airhead + */ +@Slf4j +public class TenantRedisCacheManager extends RedisCacheManager { + public TenantRedisCacheManager( + RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) { + super(cacheWriter, defaultCacheConfiguration); + } + + @Override + public Cache getCache(String name) { + if (TenantContextHolder.getTenantId() == null) { + return super.getCache(name); + } + + name = name + ":" + TenantContextHolder.getTenantId(); + return super.getCache(name); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-redis/pom.xml b/yudao-framework/yudao-spring-boot-starter-redis/pom.xml index 750cd4881..5c14c02fd 100644 --- a/yudao-framework/yudao-spring-boot-starter-redis/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-redis/pom.xml @@ -32,6 +32,12 @@ spring-boot-starter-cache + + io.netty + netty-all + 4.1.75.Final + + diff --git a/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheAutoConfiguration.java index e8c716203..6a8f92efc 100644 --- a/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheAutoConfiguration.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.framework.redis.config; import org.springframework.boot.autoconfigure.cache.CacheProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -13,6 +14,7 @@ import org.springframework.data.redis.serializer.RedisSerializer; * Cache 配置类,基于 Redis 实现 */ @Configuration +@EnableConfigurationProperties({CacheProperties.class}) @EnableCaching public class YudaoCacheAutoConfiguration { From 6b429584bfb384211bfb573a6d5303993551236d Mon Sep 17 00:00:00 2001 From: airhead Date: Thu, 25 Aug 2022 15:53:01 +0800 Subject: [PATCH 4/6] =?UTF-8?q?fix(tenant):=20=E7=A7=9F=E6=88=B7=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/YudaoTenantAutoConfiguration.java | 17 ++++++++++++----- .../core/redis/TenantRedisCacheManager.java | 6 ++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java index 7896a3ad1..8911f49d5 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java @@ -118,11 +118,18 @@ public class YudaoTenantAutoConfiguration { }; } - @Bean - @Primary - public RedisCacheManager tenantRedisCacheManager( - RedisTemplate redisTemplate, - RedisCacheConfiguration redisCacheConfiguration) { + /** + * 引入租户时,tenantRedisCacheManager为主Bean + * + * @param redisTemplate + * @param redisCacheConfiguration + * @return + */ + @Bean + @Primary + public RedisCacheManager tenantRedisCacheManager( + RedisTemplate redisTemplate, + RedisCacheConfiguration redisCacheConfiguration) { RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter( Objects.requireNonNull(redisTemplate.getConnectionFactory())); diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java index ab191f0d4..fa5adfa4d 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java @@ -8,10 +8,15 @@ import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.cache.RedisCacheWriter; /** + * 租户缓存管理 + * + * 为cacheName增加自动增加租户表示,格式:name+":"+tenantId + * * @author airhead */ @Slf4j public class TenantRedisCacheManager extends RedisCacheManager { + public TenantRedisCacheManager( RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) { super(cacheWriter, defaultCacheConfiguration); @@ -19,6 +24,7 @@ public class TenantRedisCacheManager extends RedisCacheManager { @Override public Cache getCache(String name) { + //租户未设置时,返回原始name if (TenantContextHolder.getTenantId() == null) { return super.getCache(name); } From 72883aa975cc4f51d2eed403fa593c6321e79412 Mon Sep 17 00:00:00 2001 From: airhead Date: Fri, 9 Sep 2022 23:06:58 +0800 Subject: [PATCH 5/6] =?UTF-8?q?fix(dependencies):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-dependencies/pom.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index d918cb654..866763d0a 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -132,6 +132,11 @@ yudao-spring-boot-starter-biz-error-code ${revision} + + cn.iocoder.boot + yudao-spring-boot-starter-captcha + ${revision} + @@ -454,6 +459,12 @@ ${tika-core.version} + + com.anji-plus + spring-boot-starter-captcha + ${aj-captcha.version} + + org.apache.velocity velocity-engine-core From 1be09d092bf18c641f6391900bba8beca142749e Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 24 Sep 2022 12:26:01 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E2=99=BB=EF=B8=8F=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E2=80=9C=E9=80=9A=E8=BF=87=E6=B3=A8=E8=A7=A3=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=A4=9A=E7=A7=9F=E6=88=B7=E7=BC=93=E5=AD=98=E2=80=9D=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-dependencies/pom.xml | 2 +- .../config/YudaoTenantAutoConfiguration.java | 24 +++++--------- .../core/redis/TenantRedisCacheManager.java | 33 ++++++++++--------- .../yudao-spring-boot-starter-redis/pom.xml | 1 - .../src/main/resources/application-local.yaml | 4 +-- 5 files changed, 30 insertions(+), 34 deletions(-) diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index 866763d0a..bd90ad8e7 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -58,7 +58,7 @@ 0.1.55 2.4.1 1.3.0 - 4.1.75.Final + 4.1.82.Final 8.2.2 4.6.0 diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java index 8911f49d5..7958b7a44 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java @@ -30,6 +30,7 @@ import org.springframework.context.annotation.Primary; import org.springframework.data.redis.cache.RedisCacheConfiguration; import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.cache.RedisCacheWriter; +import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import java.util.Objects; @@ -118,21 +119,14 @@ public class YudaoTenantAutoConfiguration { }; } - /** - * 引入租户时,tenantRedisCacheManager为主Bean - * - * @param redisTemplate - * @param redisCacheConfiguration - * @return - */ - @Bean - @Primary - public RedisCacheManager tenantRedisCacheManager( - RedisTemplate redisTemplate, - RedisCacheConfiguration redisCacheConfiguration) { - RedisCacheWriter cacheWriter = - RedisCacheWriter.nonLockingRedisCacheWriter( - Objects.requireNonNull(redisTemplate.getConnectionFactory())); + @Bean + @Primary // 引入租户时,tenantRedisCacheManager 为主 Bean + public RedisCacheManager tenantRedisCacheManager(RedisTemplate redisTemplate, + RedisCacheConfiguration redisCacheConfiguration) { + // 创建 RedisCacheWriter 对象 + RedisConnectionFactory connectionFactory = Objects.requireNonNull(redisTemplate.getConnectionFactory()); + RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory); + // 创建 TenantRedisCacheManager 对象 return new TenantRedisCacheManager(cacheWriter, redisCacheConfiguration); } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java index fa5adfa4d..10d62232d 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/redis/TenantRedisCacheManager.java @@ -2,34 +2,37 @@ package cn.iocoder.yudao.framework.tenant.core.redis; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; import org.springframework.cache.Cache; import org.springframework.data.redis.cache.RedisCacheConfiguration; import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.cache.RedisCacheWriter; /** - * 租户缓存管理 + * 多租户的 {@link RedisCacheManager} 实现类 * - * 为cacheName增加自动增加租户表示,格式:name+":"+tenantId + * 操作指定 name 的 {@link Cache} 时,自动拼接租户后缀,格式为 name + ":" + tenantId * * @author airhead */ @Slf4j public class TenantRedisCacheManager extends RedisCacheManager { - public TenantRedisCacheManager( - RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) { - super(cacheWriter, defaultCacheConfiguration); - } - - @Override - public Cache getCache(String name) { - //租户未设置时,返回原始name - if (TenantContextHolder.getTenantId() == null) { - return super.getCache(name); + public TenantRedisCacheManager(RedisCacheWriter cacheWriter, + RedisCacheConfiguration defaultCacheConfiguration) { + super(cacheWriter, defaultCacheConfiguration); + } + + @Override + public Cache getCache(@NotNull String name) { + // 如果开启多租户,则 name 拼接租户后缀 + if (!TenantContextHolder.isIgnore() + && TenantContextHolder.getTenantId() != null) { + name = name + ":" + TenantContextHolder.getTenantId(); + } + + // 继续基于父方法 + return super.getCache(name); } - name = name + ":" + TenantContextHolder.getTenantId(); - return super.getCache(name); - } } diff --git a/yudao-framework/yudao-spring-boot-starter-redis/pom.xml b/yudao-framework/yudao-spring-boot-starter-redis/pom.xml index 5c14c02fd..430ede255 100644 --- a/yudao-framework/yudao-spring-boot-starter-redis/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-redis/pom.xml @@ -35,7 +35,6 @@ io.netty netty-all - 4.1.75.Final diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index c26354ead..197649b5e 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -51,7 +51,7 @@ spring: # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.master.name} # SQLServer 连接的示例 username: root - password: 123456 + password: ${RUOYI_VUE_PRO} # username: sa # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W slave: # 模拟从库,可根据自己需要修改 @@ -62,7 +62,7 @@ spring: # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.slave.name} # SQLServer 连接的示例 username: root - password: 123456 + password: ${RUOYI_VUE_PRO} # username: sa # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W