!63 敏感词加载继续优化一下,初始化放在consumer中执行

Merge pull request !63 from chopper711/liushuai
This commit is contained in:
chopper711 2021-11-29 03:48:17 +00:00 committed by Gitee
commit 7170e3a16a
2 changed files with 43 additions and 2 deletions

View File

@ -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();
}
}

View File

@ -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<List<String>> cache;
/**
* 程序启动时获取最新的需要过滤的敏感词
* <p>
* 这里即便缓存中为空也没关系定时任务会定时重新加载敏感词
*
* @param args 启动参数
*/