From edc47b7b1d3e60e50dce3258e72d945845b866d3 Mon Sep 17 00:00:00 2001 From: Bull-BCLS Date: Thu, 28 Dec 2023 00:29:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(captcha):=20=E4=BF=AE=E5=A4=8D=E8=A1=8C?= =?UTF-8?q?=E4=B8=BA=E9=AA=8C=E8=AF=81=E7=A0=81=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=AE=9E=E7=8E=B0=E6=97=A0=E6=B3=95=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E5=88=B0=E7=BC=93=E5=AD=98=E5=B7=A5=E5=8E=82=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BehaviorCaptchaCacheConfiguration.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/continew-starter-captcha/continew-starter-captcha-behavior/src/main/java/top/charles7c/continew/starter/captcha/behavior/autoconfigure/BehaviorCaptchaCacheConfiguration.java b/continew-starter-captcha/continew-starter-captcha-behavior/src/main/java/top/charles7c/continew/starter/captcha/behavior/autoconfigure/BehaviorCaptchaCacheConfiguration.java index 02e70e43..2458537f 100644 --- a/continew-starter-captcha/continew-starter-captcha-behavior/src/main/java/top/charles7c/continew/starter/captcha/behavior/autoconfigure/BehaviorCaptchaCacheConfiguration.java +++ b/continew-starter-captcha/continew-starter-captcha-behavior/src/main/java/top/charles7c/continew/starter/captcha/behavior/autoconfigure/BehaviorCaptchaCacheConfiguration.java @@ -17,6 +17,8 @@ package top.charles7c.continew.starter.captcha.behavior.autoconfigure; import cn.hutool.core.util.ReflectUtil; +import cn.hutool.extra.spring.SpringUtil; +import com.anji.captcha.service.CaptchaCacheService; import com.anji.captcha.service.impl.CaptchaServiceFactory; import jakarta.annotation.PostConstruct; import lombok.AccessLevel; @@ -26,6 +28,7 @@ import org.redisson.client.RedisClient; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; import top.charles7c.continew.starter.cache.redisson.autoconfigure.RedissonAutoConfiguration; import top.charles7c.continew.starter.captcha.behavior.enums.StorageType; import top.charles7c.continew.starter.captcha.behavior.impl.BehaviorCaptchaCacheServiceImpl; @@ -63,9 +66,14 @@ abstract class BehaviorCaptchaCacheConfiguration { @NoArgsConstructor(access = AccessLevel.PRIVATE) static class Custom { + @Bean + public CaptchaCacheService captchaCacheService(BehaviorCaptchaProperties properties) { + return ReflectUtil.newInstance(properties.getCacheImpl()); + } + @PostConstruct - public void postConstruct(BehaviorCaptchaProperties properties) { - CaptchaServiceFactory.cacheService.put(StorageType.CUSTOM.name().toLowerCase(), ReflectUtil.newInstance(properties.getCacheImpl())); + public void postConstruct() { + CaptchaServiceFactory.cacheService.put(StorageType.CUSTOM.name().toLowerCase(), SpringUtil.getBean(CaptchaCacheService.class)); log.debug("[ContiNew Starter] - Auto Configuration 'Behavior-CaptchaCache-Custom' completed initialization."); } }