xiangpei
2025-05-13 9b811f9e7de77fe31e67df9396734ec9d52cdae1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package cn.lili.common.sensitive.init;
 
import cn.lili.cache.Cache;
import cn.lili.cache.CachePrefix;
import cn.lili.common.sensitive.SensitiveWordsFilter;
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;
 
/**
 * 敏感词加载
 *
 * @author Chopper
 * @version v1.0
 * 2021-11-23 12:08
 */
@Component
@Slf4j
public class SensitiveWordsLoader implements ApplicationRunner {
 
    @Autowired
    private Cache<List<String>> cache;
 
    /**
     * 程序启动时,获取最新的需要过滤的敏感词
     * <p>
     * 这里即便缓存中为空也没关系,定时任务会定时重新加载敏感词
     *
     * @param args 启动参数
     */
    @Override
    public void run(ApplicationArguments args) {
        List<String> sensitives = cache.get(CachePrefix.SENSITIVE.getPrefix());
        log.info("系统初始化敏感词");
        if (sensitives == null || sensitives.isEmpty()) {
            return;
        }
        SensitiveWordsFilter.init(sensitives);
    }
 
}