From 6b429584bfb384211bfb573a6d5303993551236d Mon Sep 17 00:00:00 2001 From: airhead Date: Thu, 25 Aug 2022 15:53:01 +0800 Subject: [PATCH] =?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); }