From 61aa3ca3d2f3a8573e13cbb80d97a26cc7c3446a Mon Sep 17 00:00:00 2001 From: Chopper Date: Mon, 29 Nov 2021 11:47:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=8F=E6=84=9F=E8=AF=8D=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E4=BC=98=E5=8C=96=E4=B8=80=E4=B8=8B=EF=BC=8C?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=94=BE=E5=9C=A8consumer=E4=B8=AD?= =?UTF-8?q?=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/lili/init/SensitiveWordsInit.java | 39 +++++++++++++++++++ ...iveInit.java => SensitiveWordsLoader.java} | 6 ++- 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 consumer/src/main/java/cn/lili/init/SensitiveWordsInit.java rename framework/src/main/java/cn/lili/common/sensitive/init/{SensitiveInit.java => SensitiveWordsLoader.java} (84%) diff --git a/consumer/src/main/java/cn/lili/init/SensitiveWordsInit.java b/consumer/src/main/java/cn/lili/init/SensitiveWordsInit.java new file mode 100644 index 00000000..a140c3de --- /dev/null +++ b/consumer/src/main/java/cn/lili/init/SensitiveWordsInit.java @@ -0,0 +1,39 @@ +package cn.lili.init; + +import cn.lili.cache.Cache; +import cn.lili.cache.CachePrefix; +import cn.lili.common.sensitive.SensitiveWordsFilter; +import cn.lili.modules.system.service.SensitiveWordsService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * SensitiveWordsInit + * + * @author Chopper + * @version v1.0 + * 2021-11-29 11:38 + */ +@Slf4j +@Component +public class SensitiveWordsInit implements ApplicationRunner { + + @Autowired + private SensitiveWordsService sensitiveWordsService; + + /** + * consumer 启动时,实时更新一下过滤词 + * + * @param args 启动参数 + */ + @Override + public void run(ApplicationArguments args) { + sensitiveWordsService.resetCache(); + } + +} \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/common/sensitive/init/SensitiveInit.java b/framework/src/main/java/cn/lili/common/sensitive/init/SensitiveWordsLoader.java similarity index 84% rename from framework/src/main/java/cn/lili/common/sensitive/init/SensitiveInit.java rename to framework/src/main/java/cn/lili/common/sensitive/init/SensitiveWordsLoader.java index bb504721..b0f5aaa1 100644 --- a/framework/src/main/java/cn/lili/common/sensitive/init/SensitiveInit.java +++ b/framework/src/main/java/cn/lili/common/sensitive/init/SensitiveWordsLoader.java @@ -12,7 +12,7 @@ import org.springframework.stereotype.Component; import java.util.List; /** - * 初始化敏感词 + * 敏感词加载 * * @author Chopper * @version v1.0 @@ -20,13 +20,15 @@ import java.util.List; */ @Component @Slf4j -public class SensitiveInit implements ApplicationRunner { +public class SensitiveWordsLoader implements ApplicationRunner { @Autowired private Cache> cache; /** * 程序启动时,获取最新的需要过滤的敏感词 + *

+ * 这里即便缓存中为空也没关系,定时任务会定时重新加载敏感词 * * @param args 启动参数 */