From 8d69be093e8ba490994b11bb51c6b23ca5ff1c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Fri, 26 May 2023 16:29:45 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20OssClient=20?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E5=A4=9A=E7=A7=9F=E6=88=B7=E7=9B=B8=E5=90=8C?= =?UTF-8?q?key=E7=BC=93=E5=AD=98=E8=A6=86=E7=9B=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/dromara/common/oss/factory/OssFactory.java | 8 +++++--- .../org/dromara/common/oss/properties/OssProperties.java | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/factory/OssFactory.java b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/factory/OssFactory.java index 084d89a5..911d9a86 100644 --- a/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/factory/OssFactory.java +++ b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/factory/OssFactory.java @@ -45,15 +45,17 @@ public class OssFactory { throw new OssException("系统异常, '" + configKey + "'配置信息不存在!"); } OssProperties properties = JsonUtils.parseObject(json, OssProperties.class); - OssClient client = CLIENT_CACHE.get(configKey); + // 使用租户标识避免多个租户相同key实例覆盖 + String key = properties.getTenantId() + ":" + configKey; + OssClient client = CLIENT_CACHE.get(key); if (client == null) { - CLIENT_CACHE.put(configKey, new OssClient(configKey, properties)); + CLIENT_CACHE.put(key, new OssClient(configKey, properties)); log.info("创建OSS实例 key => {}", configKey); return CLIENT_CACHE.get(configKey); } // 配置不相同则重新构建 if (!client.checkPropertiesSame(properties)) { - CLIENT_CACHE.put(configKey, new OssClient(configKey, properties)); + CLIENT_CACHE.put(key, new OssClient(configKey, properties)); log.info("重载OSS实例 key => {}", configKey); return CLIENT_CACHE.get(configKey); } diff --git a/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/properties/OssProperties.java b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/properties/OssProperties.java index 697530b5..cb37206e 100644 --- a/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/properties/OssProperties.java +++ b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/properties/OssProperties.java @@ -10,6 +10,11 @@ import lombok.Data; @Data public class OssProperties { + /** + * 租户id + */ + private String tenantId; + /** * 访问站点 */