From eb844e3260657b6bb9de03c1e5feca50bdf8190d 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: Wed, 17 Nov 2021 13:50:58 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20OssFactory=20?= =?UTF-8?q?=E5=9C=A8=E7=A8=8B=E5=BA=8F=E5=90=AF=E5=8A=A8=E6=9C=AA=E8=B0=83?= =?UTF-8?q?=E7=94=A8api=20=E6=B2=A1=E6=9C=89=E5=88=9D=E5=A7=8B=E5=8C=96=20?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=97=A0=E6=B3=95=E8=AE=A2=E9=98=85=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=9B=B4=E6=94=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ruoyi/oss/factory/OssFactory.java | 18 +++++++++++------- .../service/impl/SysOssConfigServiceImpl.java | 4 ++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java b/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java index ecb269dd..b5de0014 100644 --- a/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java +++ b/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java @@ -24,18 +24,22 @@ import java.util.concurrent.ConcurrentHashMap; @Slf4j public class OssFactory { - static { - RedisUtils.subscribe(CloudConstant.CACHE_CONFIG_KEY, String.class, msg -> { - refreshService(msg); - log.info("订阅刷新OSS配置 => " + msg); - }); - } - /** * 服务实例缓存 */ private static final Map SERVICES = new ConcurrentHashMap<>(); + /** + * 初始化工厂 + */ + public static void init() { + log.info("初始化OSS工厂"); + RedisUtils.subscribe(CloudConstant.CACHE_CONFIG_KEY, String.class, msg -> { + refreshService(msg); + log.info("订阅刷新OSS配置 => " + msg); + }); + } + /** * 获取默认实例 */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssConfigServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssConfigServiceImpl.java index df3f6d15..ddbf421e 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssConfigServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssConfigServiceImpl.java @@ -16,6 +16,7 @@ import com.ruoyi.common.utils.PageUtils; import com.ruoyi.common.utils.RedisUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.oss.constant.CloudConstant; +import com.ruoyi.oss.factory.OssFactory; import com.ruoyi.system.domain.SysOssConfig; import com.ruoyi.system.domain.bo.SysOssConfigBo; import com.ruoyi.system.domain.vo.SysOssConfigVo; @@ -49,6 +50,7 @@ public class SysOssConfigServiceImpl extends ServicePlusImpl list = list(); + // 加载OSS初始化配置 for (SysOssConfig config : list) { String configKey = config.getConfigKey(); if ("0".equals(config.getStatus())) { @@ -56,6 +58,8 @@ public class SysOssConfigServiceImpl extends ServicePlusImpl