From 6c053b626659311c7fc03ff47fc6da61e55e3830 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期一, 22 十一月 2021 02:45:50 +0800 Subject: [PATCH] update 优化 RedisUtils.getCacheObject 的返回值处理 --- ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java | 29 ++++++++++++++--------------- 1 files changed, 14 insertions(+), 15 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 7a22c50..b99ae0a 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 @@ -1,11 +1,9 @@ package com.ruoyi.oss.factory; -import cn.hutool.core.convert.Convert; -import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.utils.JsonUtils; +import com.ruoyi.common.utils.RedisUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.reflect.ReflectUtils; -import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.oss.constant.CloudConstant; import com.ruoyi.oss.enumd.CloudServiceEnumd; import com.ruoyi.oss.exception.OssException; @@ -25,27 +23,28 @@ @Slf4j public class OssFactory { - private static RedisCache redisCache; - - static { - OssFactory.redisCache = SpringUtils.getBean(RedisCache.class); - redisCache.subscribe(CloudConstant.CACHE_CONFIG_KEY, String.class, msg -> { - refreshService(msg); - log.info("璁㈤槄鍒锋柊OSS閰嶇疆 => " + msg); - }); - } - /** * 鏈嶅姟瀹炰緥缂撳瓨 */ private static final Map<String, ICloudStorageStrategy> SERVICES = new ConcurrentHashMap<>(); + + /** + * 鍒濆鍖栧伐鍘� + */ + public static void init() { + log.info("鍒濆鍖朞SS宸ュ巶"); + RedisUtils.subscribe(CloudConstant.CACHE_CONFIG_KEY, String.class, msg -> { + refreshService(msg); + log.info("璁㈤槄鍒锋柊OSS閰嶇疆 => " + msg); + }); + } /** * 鑾峰彇榛樿瀹炰緥 */ public static ICloudStorageStrategy instance() { // 鑾峰彇redis 榛樿绫诲瀷 - String type = Convert.toStr(redisCache.getCacheObject(CloudConstant.CACHE_CONFIG_KEY)); + String type = RedisUtils.getCacheObject(CloudConstant.CACHE_CONFIG_KEY); if (StringUtils.isEmpty(type)) { throw new OssException("鏂囦欢瀛樺偍鏈嶅姟绫诲瀷鏃犳硶鎵惧埌!"); } @@ -65,7 +64,7 @@ } private static void refreshService(String type) { - Object json = redisCache.getCacheObject(CloudConstant.SYS_OSS_KEY + type); + Object json = RedisUtils.getCacheObject(CloudConstant.SYS_OSS_KEY + type); CloudStorageProperties properties = JsonUtils.parseObject(json.toString(), CloudStorageProperties.class); if (properties == null) { throw new OssException("绯荤粺寮傚父, '" + type + "'閰嶇疆淇℃伅涓嶅瓨鍦�!"); -- Gitblit v1.9.3