diff --git a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/client/RetryEndPoint.java b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/client/RetryEndPoint.java index 0eb294c74..5b71507d1 100644 --- a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/client/RetryEndPoint.java +++ b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/client/RetryEndPoint.java @@ -8,12 +8,15 @@ import com.aizuda.easy.retry.client.core.cache.RetryerInfoCache; import com.aizuda.easy.retry.client.core.callback.RetryCompleteCallback; import com.aizuda.easy.retry.client.core.exception.EasyRetryClientException; import com.aizuda.easy.retry.client.core.intercepter.RetrySiteSnapshot; +import com.aizuda.easy.retry.client.core.loader.EasyRetrySpiLoader; import com.aizuda.easy.retry.client.core.retryer.RetryerInfo; import com.aizuda.easy.retry.client.core.retryer.RetryerResultContext; -import com.aizuda.easy.retry.client.core.loader.EasyRetrySpiLoader; import com.aizuda.easy.retry.client.core.serializer.JacksonSerializer; import com.aizuda.easy.retry.client.core.strategy.RetryStrategy; +import com.aizuda.easy.retry.client.model.DispatchRetryDTO; +import com.aizuda.easy.retry.client.model.DispatchRetryResultDTO; import com.aizuda.easy.retry.client.model.GenerateRetryIdempotentIdDTO; +import com.aizuda.easy.retry.client.model.RetryCallbackDTO; import com.aizuda.easy.retry.common.core.context.SpringContext; import com.aizuda.easy.retry.common.core.enums.RetryResultStatusEnum; import com.aizuda.easy.retry.common.core.enums.RetryStatusEnum; @@ -23,10 +26,6 @@ import com.aizuda.easy.retry.common.core.model.Result; import com.aizuda.easy.retry.common.core.util.JsonUtil; import com.aizuda.easy.retry.server.model.dto.ConfigDTO; import com.fasterxml.jackson.core.JsonProcessingException; -import com.aizuda.easy.retry.client.model.DispatchRetryDTO; -import com.aizuda.easy.retry.client.model.DispatchRetryResultDTO; -import com.aizuda.easy.retry.client.model.RetryCallbackDTO; -import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.annotation.Autowired; @@ -37,8 +36,6 @@ 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 org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; import java.lang.reflect.Method; import java.util.Objects; @@ -82,10 +79,7 @@ public class RetryEndPoint { DispatchRetryResultDTO executeRespDto = new DispatchRetryResultDTO(); try { - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - // TODO 此处用ThreadLocal替换 - HttpServletRequest request = Objects.requireNonNull(attributes).getRequest(); - request.setAttribute("attemptNumber", executeReqDto.getRetryCount()); + RetrySiteSnapshot.setAttemptNumber(executeReqDto.getRetryCount()); RetryerResultContext retryerResultContext = retryStrategy.openRetry(executeReqDto.getScene(), executeReqDto.getExecutorName(), deSerialize); @@ -106,7 +100,6 @@ public class RetryEndPoint { executeRespDto.setResultJson(JsonUtil.toJsonString(retryerResultContext.getResult())); } - } finally { RetrySiteSnapshot.removeAll(); } diff --git a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/intercepter/HeaderAspect.java b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/intercepter/HeaderAspect.java index 439977312..f05c17abd 100644 --- a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/intercepter/HeaderAspect.java +++ b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/intercepter/HeaderAspect.java @@ -5,6 +5,7 @@ import com.aizuda.easy.retry.common.core.constant.SystemConstants; import com.aizuda.easy.retry.common.core.log.LogUtils; import com.aizuda.easy.retry.common.core.model.EasyRetryHeaders; import com.aizuda.easy.retry.common.core.util.JsonUtil; +import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; @@ -13,7 +14,6 @@ import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; -import javax.servlet.http.HttpServletResponse; import java.util.Objects; /** diff --git a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/intercepter/RetrySiteSnapshot.java b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/intercepter/RetrySiteSnapshot.java index 742043a6b..1ce2cd10f 100644 --- a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/intercepter/RetrySiteSnapshot.java +++ b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/intercepter/RetrySiteSnapshot.java @@ -48,6 +48,19 @@ public class RetrySiteSnapshot { * 进入方法入口时间标记 */ private static final RetrySiteSnapshotContext ENTRY_METHOD_TIME = EasyRetrySpiLoader.loadRetrySiteSnapshotContext(); + private static final RetrySiteSnapshotContext ATTEMPT_NUMBER = EasyRetrySpiLoader.loadRetrySiteSnapshotContext(); + + public static Integer getAttemptNumber() { + return ATTEMPT_NUMBER.get(); + } + + public static void setAttemptNumber(Integer attemptNumber) { + ATTEMPT_NUMBER.set(attemptNumber); + } + + public static void removeAttemptNumber() { + ATTEMPT_NUMBER.remove(); + } public static Integer getStage() { return RETRY_STAGE.get(); @@ -156,7 +169,7 @@ public class RetrySiteSnapshot { removeStatus(); removeMethodEntrance(); removeStage(); - + removeAttemptNumber(); removeEntryMethodTime(); removeRetryHeader(); removeRetryStatusCode(); diff --git a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/strategy/RemoteRetryStrategies.java b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/strategy/RemoteRetryStrategies.java index e879a5946..5d00f912b 100644 --- a/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/strategy/RemoteRetryStrategies.java +++ b/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/strategy/RemoteRetryStrategies.java @@ -3,22 +3,17 @@ package com.aizuda.easy.retry.client.core.strategy; import com.aizuda.easy.retry.client.core.RetryExecutor; import com.aizuda.easy.retry.client.core.RetryExecutorParameter; import com.aizuda.easy.retry.client.core.intercepter.RetrySiteSnapshot; -import com.github.rholder.retry.*; -import com.google.common.base.Predicate; import com.aizuda.easy.retry.client.core.retryer.RetryType; import com.aizuda.easy.retry.client.core.retryer.RetryerInfo; import com.aizuda.easy.retry.client.core.retryer.RetryerResultContext; import com.aizuda.easy.retry.common.core.enums.RetryResultStatusEnum; import com.aizuda.easy.retry.common.core.log.LogUtils; +import com.github.rholder.retry.*; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; -import javax.servlet.http.HttpServletRequest; import java.util.Collections; import java.util.List; -import java.util.Objects; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; @@ -108,9 +103,7 @@ public class RemoteRetryStrategies extends AbstractRetryStrategies { return Collections.singletonList(new RetryListener() { @Override public void onRetry(Attempt attempt) { - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - HttpServletRequest request = Objects.requireNonNull(attributes).getRequest(); - Integer attemptNumber = (Integer) request.getAttribute("attemptNumber"); + Integer attemptNumber = RetrySiteSnapshot.getAttemptNumber(); if (attempt.hasResult()) { LogUtils.info(log, "easy-retry 远程重试成功,第[{}]次调度", attemptNumber); } diff --git a/easy-retry-client-core/src/main/resources/META-INF/spring.factories b/easy-retry-client-core/src/main/resources/META-INF/spring.factories deleted file mode 100644 index e69de29bb..000000000 diff --git a/easy-retry-client-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/easy-retry-client-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..eda4d7efa --- /dev/null +++ b/easy-retry-client-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.aizuda.easy.retry.client.starter.EasyRetryClientAutoConfiguration diff --git a/easy-retry-common/easy-retry-common-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/easy-retry-common/easy-retry-common-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..77bbc1b81 --- /dev/null +++ b/easy-retry-common/easy-retry-common-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.aizuda.easy.retry.common.core.CommonCoreConfigure \ No newline at end of file diff --git a/easy-retry-datasource/easy-retry-datasource-template/src/main/java/com/aizuda/easy/retry/template/datasource/config/EasyRetryTemplateAutoConfiguration.java b/easy-retry-datasource/easy-retry-datasource-template/src/main/java/com/aizuda/easy/retry/template/datasource/config/EasyRetryTemplateAutoConfiguration.java index c657780c9..a3d19d9d8 100644 --- a/easy-retry-datasource/easy-retry-datasource-template/src/main/java/com/aizuda/easy/retry/template/datasource/config/EasyRetryTemplateAutoConfiguration.java +++ b/easy-retry-datasource/easy-retry-datasource-template/src/main/java/com/aizuda/easy/retry/template/datasource/config/EasyRetryTemplateAutoConfiguration.java @@ -1,5 +1,7 @@ package com.aizuda.easy.retry.template.datasource.config; +import com.aizuda.easy.retry.template.datasource.access.Access; +import com.aizuda.easy.retry.template.datasource.access.AccessTemplate; import com.aizuda.easy.retry.template.datasource.enums.DbTypeEnum; import com.aizuda.easy.retry.template.datasource.utils.RequestDataHelper; import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties; @@ -27,7 +29,7 @@ import java.util.List; * @date : 2023-08-04 12:37 */ @Configuration -@ComponentScan("com.aizuda.easy.retry.template.datasource.*") +@ComponentScan("com.aizuda.easy.retry.template.datasource.**") @MapperScan(value = "com.aizuda.easy.retry.template.datasource.persistence.mapper", sqlSessionTemplateRef = "sqlSessionTemplate") public class EasyRetryTemplateAutoConfiguration { @Bean("sqlSessionFactory") diff --git a/easy-retry-datasource/easy-retry-datasource-template/src/main/resources/META-INF/spring.factories b/easy-retry-datasource/easy-retry-datasource-template/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 459184ca7..000000000 --- a/easy-retry-datasource/easy-retry-datasource-template/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.aizuda.easy.retry.template.datasource.config.EasyRetryTemplateAutoConfiguration diff --git a/easy-retry-datasource/easy-retry-datasource-template/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/easy-retry-datasource/easy-retry-datasource-template/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..e56aaa9ef --- /dev/null +++ b/easy-retry-datasource/easy-retry-datasource-template/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.aizuda.easy.retry.template.datasource.config.EasyRetryTemplateAutoConfiguration \ No newline at end of file diff --git a/easy-retry-datasource/easy-retry-mariadb-datasource/src/main/resources/META-INF/spring.factories b/easy-retry-datasource/easy-retry-mariadb-datasource/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 95ec30290..000000000 --- a/easy-retry-datasource/easy-retry-mariadb-datasource/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.aizuda.easy.retry.mariadb.datasource.config.EasyRetryMariadbAutoConfiguration diff --git a/easy-retry-datasource/easy-retry-mariadb-datasource/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/easy-retry-datasource/easy-retry-mariadb-datasource/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..c1b660540 --- /dev/null +++ b/easy-retry-datasource/easy-retry-mariadb-datasource/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.aizuda.easy.retry.mariadb.datasource.config.EasyRetryMariadbAutoConfiguration diff --git a/easy-retry-datasource/easy-retry-mysql-datasource/src/main/resources/META-INF/spring.factories b/easy-retry-datasource/easy-retry-mysql-datasource/src/main/resources/META-INF/spring.factories deleted file mode 100644 index e101a723e..000000000 --- a/easy-retry-datasource/easy-retry-mysql-datasource/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.aizuda.easy.retry.mysql.datasource.config.EasyRetryMysqlAutoConfiguration diff --git a/easy-retry-datasource/easy-retry-mysql-datasource/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/easy-retry-datasource/easy-retry-mysql-datasource/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..d9c69eb48 --- /dev/null +++ b/easy-retry-datasource/easy-retry-mysql-datasource/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.aizuda.easy.retry.mysql.datasource.config.EasyRetryMysqlAutoConfiguration \ No newline at end of file diff --git a/easy-retry-datasource/easy-retry-postgres-datasource/src/main/resources/META-INF/spring.factories b/easy-retry-datasource/easy-retry-postgres-datasource/src/main/resources/META-INF/spring.factories deleted file mode 100644 index c140ccb8b..000000000 --- a/easy-retry-datasource/easy-retry-postgres-datasource/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.aizuda.easy.retry.postgres.datasource.config.EasyRetryPostgresAutoConfiguration diff --git a/easy-retry-datasource/easy-retry-postgres-datasource/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/easy-retry-datasource/easy-retry-postgres-datasource/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..64befaad3 --- /dev/null +++ b/easy-retry-datasource/easy-retry-postgres-datasource/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.aizuda.easy.retry.postgres.datasource.config.EasyRetryPostgresAutoConfiguration diff --git a/easy-retry-server/src/main/java/com/aizuda/easy/retry/server/web/controller/SystemUserController.java b/easy-retry-server/src/main/java/com/aizuda/easy/retry/server/web/controller/SystemUserController.java index b4dd98928..0714e5793 100644 --- a/easy-retry-server/src/main/java/com/aizuda/easy/retry/server/web/controller/SystemUserController.java +++ b/easy-retry-server/src/main/java/com/aizuda/easy/retry/server/web/controller/SystemUserController.java @@ -9,10 +9,10 @@ import com.aizuda.easy.retry.server.web.annotation.LoginUser; import com.aizuda.easy.retry.server.web.annotation.LoginRequired; import com.aizuda.easy.retry.server.web.annotation.RoleEnum; import com.aizuda.easy.retry.server.web.model.response.SystemUserResponseVO; +import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import javax.validation.Valid; import java.util.List; /** diff --git a/easy-retry-server/src/main/java/com/aizuda/easy/retry/server/web/interceptor/AuthenticationInterceptor.java b/easy-retry-server/src/main/java/com/aizuda/easy/retry/server/web/interceptor/AuthenticationInterceptor.java index 346a331c7..246effb05 100644 --- a/easy-retry-server/src/main/java/com/aizuda/easy/retry/server/web/interceptor/AuthenticationInterceptor.java +++ b/easy-retry-server/src/main/java/com/aizuda/easy/retry/server/web/interceptor/AuthenticationInterceptor.java @@ -12,14 +12,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.aizuda.easy.retry.common.core.util.JsonUtil; import com.aizuda.easy.retry.server.web.annotation.LoginRequired; import com.aizuda.easy.retry.server.web.annotation.RoleEnum; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.lang.reflect.Method; import java.util.Objects; diff --git a/easy-retry-server/src/main/java/com/aizuda/easy/retry/server/web/interceptor/CORSInterceptor.java b/easy-retry-server/src/main/java/com/aizuda/easy/retry/server/web/interceptor/CORSInterceptor.java index d8611d61a..f0ebf707e 100644 --- a/easy-retry-server/src/main/java/com/aizuda/easy/retry/server/web/interceptor/CORSInterceptor.java +++ b/easy-retry-server/src/main/java/com/aizuda/easy/retry/server/web/interceptor/CORSInterceptor.java @@ -1,11 +1,10 @@ package com.aizuda.easy.retry.server.web.interceptor; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.stereotype.Component; import org.springframework.web.servlet.HandlerInterceptor; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - /** * @Author:byteblogs * @Date:2018/09/27 12:52 diff --git a/pom.xml b/pom.xml index 2b77757b3..7c56d2973 100644 --- a/pom.xml +++ b/pom.xml @@ -19,9 +19,9 @@ 17 - 1.8 - 1.8 - 2.3.0-SNAPSHOT + 17 + 17 + 3.0.0-SNAPSHOT 1.0.0 4.1.94.Final 5.8.19