From c8dc1d2bc845a32f896d63a415e1e27faa96cb4e Mon Sep 17 00:00:00 2001
From: resthx <905459569@qq.com>
Date: Fri, 28 Apr 2023 14:39:42 +0800
Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81springboot3=E6=9C=80=E6=96=B0?=
=?UTF-8?q?=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
core/captcha-spring-boot-starter/pom.xml | 16 ++++++++--------
.../AjCaptchaServiceAutoConfiguration.java | 8 +++++++-
.../captcha/controller/CaptchaController.java | 2 +-
....boot.autoconfigure.AutoConfiguration.imports | 1 +
4 files changed, 17 insertions(+), 10 deletions(-)
create mode 100644 core/captcha-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
diff --git a/core/captcha-spring-boot-starter/pom.xml b/core/captcha-spring-boot-starter/pom.xml
index e4390fb..255d9b1 100644
--- a/core/captcha-spring-boot-starter/pom.xml
+++ b/core/captcha-spring-boot-starter/pom.xml
@@ -7,7 +7,7 @@
org.springframework.boot
spring-boot-starter-parent
- 2.0.4.RELEASE
+ 3.0.6
com.anji-plus
@@ -21,7 +21,7 @@
1.8
- 2.0.4.RELEASE
+ 3.0.6
@@ -83,17 +83,17 @@
org.apache.maven.plugins
maven-compiler-plugin
- 3.3
+ 3.8.1
-
- 1.8
+
+
UTF-8
org.apache.maven.plugins
maven-resources-plugin
- 2.4
+ 3.1.0
UTF-8
@@ -101,7 +101,7 @@
org.apache.maven.plugins
maven-source-plugin
- 2.2.1
+ 3.2.1
attach-sources
@@ -114,7 +114,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 2.9.1
+ 3.4.1
attach-javadocs
diff --git a/core/captcha-spring-boot-starter/src/main/java/com/anji/captcha/config/AjCaptchaServiceAutoConfiguration.java b/core/captcha-spring-boot-starter/src/main/java/com/anji/captcha/config/AjCaptchaServiceAutoConfiguration.java
index dfc048b..0ca6b6c 100644
--- a/core/captcha-spring-boot-starter/src/main/java/com/anji/captcha/config/AjCaptchaServiceAutoConfiguration.java
+++ b/core/captcha-spring-boot-starter/src/main/java/com/anji/captcha/config/AjCaptchaServiceAutoConfiguration.java
@@ -3,6 +3,7 @@ package com.anji.captcha.config;
import com.anji.captcha.model.common.Const;
import com.anji.captcha.properties.AjCaptchaProperties;
+import com.anji.captcha.service.CaptchaCacheService;
import com.anji.captcha.service.CaptchaService;
import com.anji.captcha.service.impl.CaptchaServiceFactory;
import com.anji.captcha.util.ImageUtils;
@@ -19,6 +20,7 @@ import org.springframework.util.Base64Utils;
import org.springframework.util.FileCopyUtils;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -29,7 +31,7 @@ public class AjCaptchaServiceAutoConfiguration {
@Bean
@ConditionalOnMissingBean
- public CaptchaService captchaService(AjCaptchaProperties prop) {
+ public CaptchaService captchaService(AjCaptchaProperties prop, List captchaCacheServiceList) {
logger.info("自定义配置项:{}", prop.toString());
Properties config = new Properties();
config.put(Const.CAPTCHA_CACHETYPE, prop.getCacheType().name());
@@ -64,7 +66,11 @@ public class AjCaptchaServiceAutoConfiguration {
config.put(Const.CAPTCHA_INIT_ORIGINAL, "true");
initializeBaseMap(prop.getJigsaw(), prop.getPicClick());
}
+ //使springboot可以通过注入bena加载相关CaptchaCacheService
CaptchaService s = CaptchaServiceFactory.getInstance(config);
+ for (CaptchaCacheService captchaCacheService : captchaCacheServiceList) {
+ CaptchaServiceFactory.cacheService.putIfAbsent(captchaCacheService.type(), captchaCacheService);
+ }
return s;
}
diff --git a/core/captcha-spring-boot-starter/src/main/java/com/anji/captcha/controller/CaptchaController.java b/core/captcha-spring-boot-starter/src/main/java/com/anji/captcha/controller/CaptchaController.java
index 468833e..0247904 100644
--- a/core/captcha-spring-boot-starter/src/main/java/com/anji/captcha/controller/CaptchaController.java
+++ b/core/captcha-spring-boot-starter/src/main/java/com/anji/captcha/controller/CaptchaController.java
@@ -10,13 +10,13 @@ import com.anji.captcha.model.common.ResponseModel;
import com.anji.captcha.model.vo.CaptchaVO;
import com.anji.captcha.service.CaptchaService;
import com.anji.captcha.util.StringUtils;
+import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
-import javax.servlet.http.HttpServletRequest;
@RestController
diff --git a/core/captcha-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/core/captcha-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 0000000..4a295be
--- /dev/null
+++ b/core/captcha-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1 @@
+com.anji.captcha.config.AjCaptchaAutoConfiguration
--
Gitee