com.taotao.boot.sensitive.word.SensitiveWordsRunner Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2020-2030, Shuigedeng ([email protected] & https://blog.taotaocloud.top/).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.taotao.boot.sensitive.word;
import com.taotao.boot.cache.redis.repository.RedisRepository;
import com.taotao.boot.common.constant.RedisConstant;
import com.taotao.boot.common.utils.log.LogUtils;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import java.util.List;
import java.util.Objects;
/** 敏感词加载 */
public class SensitiveWordsRunner implements ApplicationRunner {
private final RedisRepository redisRepository;
public SensitiveWordsRunner(RedisRepository redisRepository) {
this.redisRepository = redisRepository;
}
/**
* 程序启动时,获取最新的需要过滤的敏感词
*
* 这里即便缓存中为空也没关系,定时任务会定时重新加载敏感词
*
* @param args 启动参数
*/
@Override
@SuppressWarnings("unchecked")
public void run(ApplicationArguments args) {
Object words = redisRepository.get(RedisConstant.SENSITIVE_WORDS_KEY);
if (Objects.nonNull(words)) {
LogUtils.info("系统初始化敏感词");
List sensitives = (List) words;
if (sensitives.isEmpty()) {
return;
}
SensitiveWordsFilter.init(sensitives);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy