From 1b822862bf86c871d9663fc99b2de2213cc40e5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= <2270033969@qq.com> Date: Mon, 8 Jul 2024 13:41:45 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Introducing=20new=20features.=20?= =?UTF-8?q?=E3=80=90=E7=B3=BB=E7=BB=9F=E7=AE=A1=E7=90=86=E3=80=91=E6=95=8F?= =?UTF-8?q?=E6=84=9F=E8=AF=8D=E7=BB=B4=E6=8A=A4=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 7be72d3fcb8a611e1a1bc6f7510c0a498d23aa97) --- .../sensitive/SensitiveAutoConfiguration.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/pigx-common/pigx-common-sensitive/src/main/java/com/pig4cloud/pigx/common/sensitive/SensitiveAutoConfiguration.java b/pigx-common/pigx-common-sensitive/src/main/java/com/pig4cloud/pigx/common/sensitive/SensitiveAutoConfiguration.java index c932e72d3..dc94d3a36 100644 --- a/pigx-common/pigx-common-sensitive/src/main/java/com/pig4cloud/pigx/common/sensitive/SensitiveAutoConfiguration.java +++ b/pigx-common/pigx-common-sensitive/src/main/java/com/pig4cloud/pigx/common/sensitive/SensitiveAutoConfiguration.java @@ -8,14 +8,15 @@ import com.pig4cloud.pigx.common.sensitive.core.SensitiveService; import com.pig4cloud.pigx.common.sensitive.util.RemoteSensitiveService; import com.pig4cloud.pigx.common.sensitive.util.SensitiveWordsProperties; import com.pig4cloud.pigx.common.sensitive.word.SensitiveWordCustomizer; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; -import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.listener.ChannelTopic; import org.springframework.data.redis.listener.RedisMessageListenerContainer; import org.springframework.security.core.Authentication; @@ -32,9 +33,12 @@ import java.util.Objects; */ @Slf4j @AutoConfiguration +@RequiredArgsConstructor @Configuration(proxyBeanMethods = false) @EnableConfigurationProperties(SensitiveWordsProperties.class) -public class SensitiveAutoConfiguration { +public class SensitiveAutoConfiguration implements InitializingBean { + + private final RedisMessageListenerContainer redisMessageListenerContainer; /** * 注入默认的脱敏权限判断 @@ -106,23 +110,14 @@ public class SensitiveAutoConfiguration { .init(); } - /** - * redis 监听配置 - * - * @param redisConnectionFactory redis 配置 - * @return - */ - @Bean - public RedisMessageListenerContainer redisContainer(RedisConnectionFactory redisConnectionFactory) { - RedisMessageListenerContainer container = new RedisMessageListenerContainer(); - container.setConnectionFactory(redisConnectionFactory); - container.addMessageListener((message, bytes) -> { + + @Override + public void afterPropertiesSet() throws Exception { + redisMessageListenerContainer.addMessageListener((message, bytes) -> { log.info("开始重新加载敏感词库"); SpringContextHolder.getBean(SensitiveWordBs.class).init(); log.info("敏感词库加载完成"); }, new ChannelTopic(CacheConstants.SENSITIVE_REDIS_RELOAD_TOPIC)); - return container; } - }