From e495c8541948655d9a4713ea03439ce17cbca0ad Mon Sep 17 00:00:00 2001 From: liaozan <378024053@qq.com> Date: Sat, 24 Jun 2023 16:44:56 +0800 Subject: [PATCH] Polish --- .../excel/listener/ExcelReadListenerBase.java | 10 +-- .../HierarchicalDataReadListener.java | 8 +- .../schbrain/common/util/ValidateUtils.java | 48 +++++++++++ .../web/ExceptionHandingConfiguration.java | 17 ++-- .../web/ServletComponentConfiguration.java | 6 +- .../web/WebCommonAutoConfiguration.java | 8 +- .../DefaultGlobalExceptionResolver.java | 9 +- .../ExceptionHandingWebMvcConfigurer.java | 2 +- .../common/web/log/RequestLoggingFilter.java | 12 +-- .../web/result/ResponseBodyHandler.java | 20 +---- .../TraceIdInitializeServletListener.java | 12 +-- .../web/support/BaseHandlerInterceptor.java | 8 +- .../authentication/AbstractAuthenticator.java | 8 +- .../AuthenticationInterceptor.java | 8 +- .../support/authentication/Authenticator.java | 2 +- pom.xml | 4 +- .../apollo/ConfigurablePropertiesLoader.java | 2 +- .../cache/CacheAutoConfiguration.java | 9 +- .../autoconfigure/cache/CacheUtils.java | 28 +++---- .../cache/provider/CacheProvider.java | 35 ++++---- .../cache/provider/CacheProviderDelegate.java | 81 ++++++++---------- .../provider/redis/RedisCacheProvider.java | 80 +++++++++--------- .../LoggerConfigLoadedEventListener.java | 7 +- .../DataSourcePropertiesExtractorSupport.java | 4 +- .../DruidDataSourcePropertiesExtractor.java | 2 +- .../HikariDataSourcePropertiesExtractor.java | 2 +- .../xxl/SchbrainXxlJobExecutor.java | 83 ------------------- .../xxl/XxlJobAutoConfiguration.java | 7 +- .../com/schbrain/framework/dao/BaseDao.java | 10 +-- 29 files changed, 230 insertions(+), 302 deletions(-) delete mode 100644 starters/xxl-job-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/xxl/SchbrainXxlJobExecutor.java diff --git a/commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/ExcelReadListenerBase.java b/commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/ExcelReadListenerBase.java index a174c21..78cc1bd 100644 --- a/commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/ExcelReadListenerBase.java +++ b/commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/ExcelReadListenerBase.java @@ -37,6 +37,11 @@ public class ExcelReadListenerBase extends AnalysisEventListener { this.headers = headMap; } + @Override + public void onException(Exception exception, AnalysisContext context) { + throw new ExcelException(exception.getMessage(), exception); + } + @Override public void invoke(T data, AnalysisContext context) { boolean validated = validate(data, context); @@ -48,11 +53,6 @@ public class ExcelReadListenerBase extends AnalysisEventListener { this.dataList.add(data); } - @Override - public void onException(Exception exception, AnalysisContext context) { - throw new ExcelException(exception.getMessage(), exception); - } - @Override public void doAfterAllAnalysed(AnalysisContext context) { } diff --git a/commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/HierarchicalDataReadListener.java b/commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/HierarchicalDataReadListener.java index d658f76..88a6284 100644 --- a/commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/HierarchicalDataReadListener.java +++ b/commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/HierarchicalDataReadListener.java @@ -36,10 +36,6 @@ public class HierarchicalDataReadListener extends ExcelReadListenerBase getImportedRecords() { - return importedRecords; - } - @Override protected boolean validate(Map data, AnalysisContext context) { Integer rowIndex = context.readRowHolder().getRowIndex(); @@ -54,6 +50,10 @@ public class HierarchicalDataReadListener extends ExcelReadListenerBase getImportedRecords() { + return importedRecords; + } + protected void buildImportedRow(Integer rowIndex, Integer columnIndex, String text) { ImportedRecord importedRecord = new ImportedRecord(); importedRecord.setText(text); diff --git a/commons/common/src/main/java/com/schbrain/common/util/ValidateUtils.java b/commons/common/src/main/java/com/schbrain/common/util/ValidateUtils.java index 2ac7054..8388c49 100644 --- a/commons/common/src/main/java/com/schbrain/common/util/ValidateUtils.java +++ b/commons/common/src/main/java/com/schbrain/common/util/ValidateUtils.java @@ -15,6 +15,10 @@ public class ValidateUtils { private ValidateUtils() { } + public static void isTrue(boolean expression) { + isTrue(expression, "操作有误"); + } + public static void isTrue(boolean expression, String message) { isTrue(expression, () -> new ParamInvalidException(message)); } @@ -25,6 +29,10 @@ public class ValidateUtils { } } + public static void isFalse(boolean expression) { + isFalse(expression, "操作有误"); + } + public static void isFalse(boolean expression, String message) { isFalse(expression, () -> new ParamInvalidException(message)); } @@ -35,6 +43,10 @@ public class ValidateUtils { } } + public static void notNull(Object object) { + notNull(object, "The validated object is null"); + } + public static void notNull(Object object, String message) { notNull(object, () -> new ParamInvalidException(message)); } @@ -45,6 +57,10 @@ public class ValidateUtils { } } + public static void isNull(Object object) { + isNull(object, "The validated object is not null"); + } + public static void isNull(Object object, String message) { isNull(object, () -> new ParamInvalidException(message)); } @@ -55,6 +71,10 @@ public class ValidateUtils { } } + public static void notEmpty(String value) { + notEmpty(value, "The validated string is empty"); + } + public static void notEmpty(String value, String message) { notEmpty(value, () -> new ParamInvalidException(message)); } @@ -65,6 +85,10 @@ public class ValidateUtils { } } + public static void isEmpty(String value) { + isEmpty(value, "The validated string is not empty"); + } + public static void isEmpty(String value, String message) { isEmpty(value, () -> new ParamInvalidException(message)); } @@ -75,6 +99,10 @@ public class ValidateUtils { } } + public static void notEmpty(Object[] array) { + notEmpty(array, "The validated array is empty"); + } + public static void notEmpty(Object[] array, String message) { notEmpty(array, () -> new ParamInvalidException(message)); } @@ -85,6 +113,10 @@ public class ValidateUtils { } } + public static void isEmpty(Object[] array) { + isEmpty(array, "The validated array is not empty"); + } + public static void isEmpty(Object[] array, String message) { isEmpty(array, () -> new ParamInvalidException(message)); } @@ -95,6 +127,10 @@ public class ValidateUtils { } } + public static void notEmpty(Collection collection) { + notEmpty(collection, "The validated collection is empty"); + } + public static void notEmpty(Collection collection, String message) { notEmpty(collection, () -> new ParamInvalidException(message)); } @@ -105,6 +141,10 @@ public class ValidateUtils { } } + public static void isEmpty(Collection collection) { + isEmpty(collection, "The validated collection is not empty"); + } + public static void isEmpty(Collection collection, String message) { isEmpty(collection, () -> new ParamInvalidException(message)); } @@ -115,6 +155,10 @@ public class ValidateUtils { } } + public static void notEmpty(Map map) { + notEmpty(map, "The validated map is empty"); + } + public static void notEmpty(Map map, String message) { notEmpty(map, () -> new ParamInvalidException(message)); } @@ -125,6 +169,10 @@ public class ValidateUtils { } } + public static void isEmpty(Map map) { + isEmpty(map, "The validated map is not empty"); + } + public static void isEmpty(Map map, String message) { isEmpty(map, () -> new ParamInvalidException(message)); } diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/ExceptionHandingConfiguration.java b/commons/web-common/src/main/java/com/schbrain/common/web/ExceptionHandingConfiguration.java index 2333b66..5c1a632 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/ExceptionHandingConfiguration.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/ExceptionHandingConfiguration.java @@ -3,8 +3,8 @@ package com.schbrain.common.web; import com.schbrain.common.web.exception.*; import com.schbrain.common.web.properties.WebProperties; import org.springframework.beans.factory.ObjectProvider; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -15,24 +15,25 @@ import java.util.stream.Collectors; * @since 2023-05-08 */ @Configuration(proxyBeanMethods = false) +@ConditionalOnProperty(value = "schbrain.web.enable-global-exception-handler", havingValue = "true", matchIfMissing = true) public class ExceptionHandingConfiguration { @Bean - public GlobalExceptionHandler defaultGlobalExceptionHandler(ObjectProvider exceptionTranslators) { - return new GlobalExceptionHandler(exceptionTranslators.orderedStream().collect(Collectors.toList())); + @ConditionalOnMissingBean + public ExceptionTranslator defaultExceptionTranslator() { + return new DefaultExceptionTranslator(); } @Bean @ConditionalOnMissingBean - public ExceptionHandingWebMvcConfigurer defaultExceptionHandingWebMvcConfigurer(WebProperties webProperties, GlobalExceptionHandler exceptionHandler) { - return new ExceptionHandingWebMvcConfigurer(webProperties, exceptionHandler); + public GlobalExceptionHandler defaultGlobalExceptionHandler(ObjectProvider exceptionTranslators) { + return new GlobalExceptionHandler(exceptionTranslators.orderedStream().collect(Collectors.toList())); } @Bean @ConditionalOnMissingBean - @ConditionalOnBean(GlobalExceptionHandler.class) - public ExceptionTranslator defaultExceptionTranslator() { - return new DefaultExceptionTranslator(); + public ExceptionHandingWebMvcConfigurer defaultExceptionHandingWebMvcConfigurer(WebProperties webProperties, GlobalExceptionHandler exceptionHandler) { + return new ExceptionHandingWebMvcConfigurer(webProperties, exceptionHandler); } } \ No newline at end of file diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/ServletComponentConfiguration.java b/commons/web-common/src/main/java/com/schbrain/common/web/ServletComponentConfiguration.java index a8efd56..9e8ea5d 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/ServletComponentConfiguration.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/ServletComponentConfiguration.java @@ -4,6 +4,7 @@ import com.schbrain.common.web.log.RequestLoggingFilter; import com.schbrain.common.web.properties.WebProperties; import com.schbrain.common.web.servlet.CharacterEncodingServletContextInitializer; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -32,8 +33,9 @@ public class ServletComponentConfiguration { @Bean @ConditionalOnMissingBean - public RequestLoggingFilter requestLoggingFilter(WebProperties properties) { - return new RequestLoggingFilter(properties); + @ConditionalOnProperty(value = "schbrain.web.enable-request-logging", havingValue = "true", matchIfMissing = true) + public RequestLoggingFilter requestLoggingFilter() { + return new RequestLoggingFilter(); } } \ No newline at end of file diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/WebCommonAutoConfiguration.java b/commons/web-common/src/main/java/com/schbrain/common/web/WebCommonAutoConfiguration.java index 933c8b7..e0cdd87 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/WebCommonAutoConfiguration.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/WebCommonAutoConfiguration.java @@ -9,8 +9,7 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigurationPackages; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.condition.*; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.client.RestTemplateBuilder; @@ -48,9 +47,10 @@ public class WebCommonAutoConfiguration { @Bean @ConditionalOnMissingBean - public ResponseBodyHandler defaultResponseBodyHandler(WebProperties properties, BeanFactory beanFactory) { + @ConditionalOnProperty(value = "schbrain.web.wrap-response", havingValue = "true", matchIfMissing = true) + public ResponseBodyHandler defaultResponseBodyHandler(BeanFactory beanFactory) { List basePackages = AutoConfigurationPackages.get(beanFactory); - return new ResponseBodyHandler(properties, basePackages); + return new ResponseBodyHandler(basePackages); } @Bean diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/exception/DefaultGlobalExceptionResolver.java b/commons/web-common/src/main/java/com/schbrain/common/web/exception/DefaultGlobalExceptionResolver.java index c7dd6e4..5771cd6 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/exception/DefaultGlobalExceptionResolver.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/exception/DefaultGlobalExceptionResolver.java @@ -1,7 +1,6 @@ package com.schbrain.common.web.exception; import com.schbrain.common.web.annotation.ResponseWrapOption; -import com.schbrain.common.web.properties.WebProperties; import com.schbrain.common.web.utils.HandlerMethodAnnotationUtils; import lombok.EqualsAndHashCode; import lombok.extern.slf4j.Slf4j; @@ -29,7 +28,7 @@ import java.util.concurrent.ConcurrentHashMap; @EqualsAndHashCode(callSuper = true) public class DefaultGlobalExceptionResolver extends AbstractHandlerMethodExceptionResolver { - private final WebProperties webProperties; + private final boolean wrapResponse; private final GlobalExceptionHandler exceptionHandler; @@ -41,8 +40,8 @@ public class DefaultGlobalExceptionResolver extends AbstractHandlerMethodExcepti private final Map, ExceptionHandlerMethodResolver> exceptionHandlerMethodResolvers = new ConcurrentHashMap<>(64); - public DefaultGlobalExceptionResolver(ExceptionHandlerExceptionResolver handlerMethodResolver, WebProperties webProperties, GlobalExceptionHandler exceptionHandler) { - this.webProperties = webProperties; + public DefaultGlobalExceptionResolver(ExceptionHandlerExceptionResolver handlerMethodResolver, boolean wrapResponse, GlobalExceptionHandler exceptionHandler) { + this.wrapResponse = wrapResponse; this.exceptionHandler = exceptionHandler; this.handlerMethodResolver = new ExceptionHandlerMethodResolver(exceptionHandler.getClass()); this.argumentResolverComposite = handlerMethodResolver.getArgumentResolvers(); @@ -52,7 +51,7 @@ public class DefaultGlobalExceptionResolver extends AbstractHandlerMethodExcepti @Override protected boolean shouldApplyTo(HttpServletRequest request, @Nullable Object handler) { - if (!webProperties.isWrapResponse()) { + if (!wrapResponse) { return false; } diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/exception/ExceptionHandingWebMvcConfigurer.java b/commons/web-common/src/main/java/com/schbrain/common/web/exception/ExceptionHandingWebMvcConfigurer.java index 1410be9..da716b2 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/exception/ExceptionHandingWebMvcConfigurer.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/exception/ExceptionHandingWebMvcConfigurer.java @@ -49,7 +49,7 @@ public class ExceptionHandingWebMvcConfigurer implements WebMvcConfigurer { } protected HandlerExceptionResolver createExceptionResolver(ExceptionHandlerExceptionResolver adviceExceptionResolver) { - return new DefaultGlobalExceptionResolver(adviceExceptionResolver, webProperties, globalExceptionHandler); + return new DefaultGlobalExceptionResolver(adviceExceptionResolver, webProperties.isWrapResponse(), globalExceptionHandler); } } \ No newline at end of file diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/log/RequestLoggingFilter.java b/commons/web-common/src/main/java/com/schbrain/common/web/log/RequestLoggingFilter.java index dcdb11f..2f18cd8 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/log/RequestLoggingFilter.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/log/RequestLoggingFilter.java @@ -2,7 +2,6 @@ package com.schbrain.common.web.log; import cn.hutool.core.text.CharPool; import cn.hutool.core.util.ArrayUtil; -import com.schbrain.common.web.properties.WebProperties; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.web.servlet.filter.OrderedFilter; import org.springframework.core.Ordered; @@ -27,15 +26,9 @@ import static com.schbrain.common.web.utils.ContentCachingServletUtils.wrapReque @Slf4j public class RequestLoggingFilter extends OncePerRequestFilter implements OrderedFilter { - private final WebProperties webProperties; - - public RequestLoggingFilter(WebProperties webProperties) { - this.webProperties = webProperties; - } - @Override public int getOrder() { - return Ordered.HIGHEST_PRECEDENCE; + return Ordered.HIGHEST_PRECEDENCE + 10; } @Override @@ -57,9 +50,6 @@ public class RequestLoggingFilter extends OncePerRequestFilter implements Ordere } protected boolean shouldSkip(HttpServletRequest request) { - if (!webProperties.isEnableRequestLogging()) { - return true; - } return CorsUtils.isPreFlightRequest(request); } diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/result/ResponseBodyHandler.java b/commons/web-common/src/main/java/com/schbrain/common/web/result/ResponseBodyHandler.java index 21892d1..592fb93 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/result/ResponseBodyHandler.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/result/ResponseBodyHandler.java @@ -1,7 +1,6 @@ package com.schbrain.common.web.result; import com.schbrain.common.web.annotation.ResponseWrapOption; -import com.schbrain.common.web.properties.WebProperties; import org.springframework.core.MethodParameter; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; @@ -22,34 +21,23 @@ import java.util.concurrent.ConcurrentHashMap; @RestControllerAdvice public class ResponseBodyHandler implements ResponseBodyAdvice { - private final WebProperties webProperties; - private final List basePackages; - private final Map methodCache; + private final Map methodCache = new ConcurrentHashMap<>(); - public ResponseBodyHandler(WebProperties webProperties, List basePackages) { - this.webProperties = webProperties; + public ResponseBodyHandler(List basePackages) { this.basePackages = basePackages; - this.methodCache = new ConcurrentHashMap<>(); } @Override public boolean supports(MethodParameter returnType, Class> converterType) { - if (!webProperties.isWrapResponse()) { - return false; - } return methodCache.computeIfAbsent(returnType.getMethod(), this::shouldApply); } @Override - public Object beforeBodyWrite(Object body, MethodParameter returnType, - MediaType selectedContentType, Class> selectedConverterType, + public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, + Class> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) { - return beforeBodyWrite(body); - } - - protected Object beforeBodyWrite(Object body) { if (body instanceof ResponseDTO) { return body; } diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/servlet/TraceIdInitializeServletListener.java b/commons/web-common/src/main/java/com/schbrain/common/web/servlet/TraceIdInitializeServletListener.java index 759fcd7..82cf298 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/servlet/TraceIdInitializeServletListener.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/servlet/TraceIdInitializeServletListener.java @@ -11,16 +11,16 @@ import javax.servlet.ServletRequestListener; */ public class TraceIdInitializeServletListener implements ServletRequestListener { - @Override - public void requestInitialized(ServletRequestEvent event) { - // Make sure the traceId is initialized - TraceIdUtils.get(); - } - @Override public void requestDestroyed(ServletRequestEvent event) { // Make sure the traceId can be cleared TraceIdUtils.clear(); } + @Override + public void requestInitialized(ServletRequestEvent event) { + // Make sure the traceId is initialized + TraceIdUtils.get(); + } + } \ No newline at end of file diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/support/BaseHandlerInterceptor.java b/commons/web-common/src/main/java/com/schbrain/common/web/support/BaseHandlerInterceptor.java index 2e018d0..9214303 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/support/BaseHandlerInterceptor.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/support/BaseHandlerInterceptor.java @@ -46,19 +46,19 @@ public class BaseHandlerInterceptor implements AsyncHandlerInterceptor { } } - protected boolean preHandle(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler) throws Exception { + protected boolean preHandle(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception { return true; } - protected void postHandle(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler, ModelAndView modelAndView) throws Exception { + protected void postHandle(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod, ModelAndView modelAndView) throws Exception { } - protected void afterCompletion(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler, Exception ex) throws Exception { + protected void afterCompletion(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod, Exception ex) throws Exception { } - protected void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) { + protected void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception { } diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AbstractAuthenticator.java b/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AbstractAuthenticator.java index 0ee9684..7155a8c 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AbstractAuthenticator.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AbstractAuthenticator.java @@ -34,8 +34,8 @@ public abstract class AbstractAuthenticator implements Authenticator { } @Override - public boolean validate(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler) { - boolean ignore = HandlerMethodAnnotationUtils.hasAnnotation(handler, IgnoreLogin.class); + public boolean validate(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) { + boolean ignore = HandlerMethodAnnotationUtils.hasAnnotation(handlerMethod, IgnoreLogin.class); if (ignore) { return true; } @@ -43,10 +43,10 @@ public abstract class AbstractAuthenticator implements Authenticator { if (StringUtils.isBlank(authentication)) { return false; } - return doValidate(authentication, request, response, handler); + return doValidate(authentication, request, response, handlerMethod); } - protected abstract boolean doValidate(String authentication, HttpServletRequest request, HttpServletResponse response, HandlerMethod handler); + protected abstract boolean doValidate(String authentication, HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod); @Nullable protected String getAuthentication(HttpServletRequest request) { diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AuthenticationInterceptor.java b/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AuthenticationInterceptor.java index 678339e..62e5ec6 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AuthenticationInterceptor.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AuthenticationInterceptor.java @@ -38,8 +38,8 @@ public class AuthenticationInterceptor extends BaseHandlerInterceptor implements } @Override - protected boolean preHandle(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler) { - boolean validated = authenticator.validate(request, response, handler); + protected boolean preHandle(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) { + boolean validated = authenticator.validate(request, response, handlerMethod); if (validated) { return true; } @@ -48,8 +48,8 @@ public class AuthenticationInterceptor extends BaseHandlerInterceptor implements } @Override - protected void afterCompletion(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler, Exception ex) { - authenticator.afterCompletion(request, response, handler, ex); + protected void afterCompletion(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod, Exception ex) { + authenticator.afterCompletion(request, response, handlerMethod, ex); } protected void writeResult(HttpServletResponse response, ResponseDTO result) { diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/Authenticator.java b/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/Authenticator.java index 0a45535..c9064c2 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/Authenticator.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/Authenticator.java @@ -19,6 +19,6 @@ public interface Authenticator { /** * 请求完成后的回调 */ - void afterCompletion(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler, Exception exception); + void afterCompletion(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod, Exception exception); } \ No newline at end of file diff --git a/pom.xml b/pom.xml index aa79e67..b625f77 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,7 @@ 32.0.1-jre 5.8.20 3.0.2 - 7.4 + 7.3 3.5.13 2.3.0 3.5.3.1 @@ -785,4 +785,4 @@ - + \ No newline at end of file diff --git a/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ConfigurablePropertiesLoader.java b/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ConfigurablePropertiesLoader.java index fc1838f..6e2223a 100644 --- a/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ConfigurablePropertiesLoader.java +++ b/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ConfigurablePropertiesLoader.java @@ -54,7 +54,7 @@ class ConfigurablePropertiesLoader { ApolloProperties apolloProperties = ApolloProperties.get(environment); - // MUST NOT use CachedCompositePropertySource + // MUST NOT use CachedCompositePropertySource, because propertyNames will be cached when property loading CompositePropertySource compositePropertySource = new CompositePropertySource(PROPERTIES_PROPERTY_SOURCE); if (apolloProperties.isRemoteFirst()) { environment.getPropertySources().addFirst(compositePropertySource); diff --git a/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/CacheAutoConfiguration.java b/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/CacheAutoConfiguration.java index 6056e84..72540ee 100644 --- a/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/CacheAutoConfiguration.java +++ b/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/CacheAutoConfiguration.java @@ -10,7 +10,6 @@ import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; -import org.springframework.core.env.Environment; /** * AutoConfiguration for schbrain cache @@ -25,10 +24,10 @@ public class CacheAutoConfiguration { @Bean @ConditionalOnBean(CacheProvider.class) - public CacheProvider cacheProvider(CacheProvider cacheProvider, CacheProperties cacheProperties, Environment environment) { - CacheProviderDelegate delegate = new CacheProviderDelegate(cacheProperties, cacheProvider, environment); - CacheUtils.setCacheProvider(delegate); - return delegate; + public CacheProvider cacheProvider(CacheProvider cacheProvider, CacheProperties cacheProperties) { + CacheProvider provider = new CacheProviderDelegate(cacheProperties, cacheProvider); + CacheUtils.setCacheProvider(provider); + return provider; } } \ No newline at end of file diff --git a/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/CacheUtils.java b/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/CacheUtils.java index ab92256..414c67e 100644 --- a/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/CacheUtils.java +++ b/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/CacheUtils.java @@ -46,6 +46,20 @@ public class CacheUtils { return getCacheProvider().getExpire(cacheKey); } + /** + * 模糊搜索 key, 默认采用 scan 实现 + */ + public static Set keys(String pattern) { + return keys(pattern, Long.MAX_VALUE); + } + + /** + * 模糊搜索 key, 默认采用 scan 实现 + */ + public static Set keys(String pattern, long limit) { + return getCacheProvider().keys(pattern, limit); + } + /** * 获取缓存数据 */ @@ -161,18 +175,4 @@ public class CacheUtils { getCacheProvider().del(cacheKeys); } - /** - * 模糊搜索 key, 默认采用 scan 实现 - */ - public static Set keys(String pattern) { - return keys(pattern, Long.MAX_VALUE); - } - - /** - * 模糊搜索 key, 默认采用 scan 实现 - */ - public static Set keys(String pattern, long limit) { - return getCacheProvider().keys(pattern, limit); - } - } \ No newline at end of file diff --git a/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProvider.java b/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProvider.java index 70337f4..fbb95b7 100644 --- a/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProvider.java +++ b/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProvider.java @@ -1,10 +1,7 @@ package com.schbrain.framework.autoconfigure.cache.provider; import java.time.Duration; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * @author zhuyf @@ -12,6 +9,11 @@ import java.util.Set; **/ public interface CacheProvider { + /** + * 查询key是否过期 + */ + boolean isExpired(String cacheKey); + /** * 指定缓存失效时间 */ @@ -27,30 +29,20 @@ public interface CacheProvider { */ boolean hasKey(String cacheKey); - /** - * 删除缓存 - */ - void del(List cacheKeys); - /** * 模糊搜索 key, 默认采用 scan 实现 */ Set keys(String pattern, long limit); /** - * 缓存获取 + * 删除缓存 */ - T get(String cacheKey, Class valueType); + void del(List cacheKeys); /** * 缓存获取 */ - Map multiGet(Collection cacheKeys, Class valueType, boolean discardIfValueIsNull); - - /** - * list 缓存获取 - */ - List getList(String cacheKey, Class valueType); + T get(String cacheKey, Class valueType); /** * 缓存放入并设置时间 @@ -63,8 +55,13 @@ public interface CacheProvider { void multiSet(Map data, Duration expiration); /** - * 查询key是否过期 + * 缓存获取 */ - boolean isExpired(String cacheKey); + Map multiGet(Collection cacheKeys, Class valueType, boolean discardIfValueIsNull); + + /** + * list 缓存获取 + */ + List getList(String cacheKey, Class valueType); } \ No newline at end of file diff --git a/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProviderDelegate.java b/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProviderDelegate.java index 0405ffe..f2d5688 100644 --- a/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProviderDelegate.java +++ b/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProviderDelegate.java @@ -8,7 +8,6 @@ import com.schbrain.framework.autoconfigure.cache.properties.CacheProperties; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.springframework.core.env.Environment; import java.time.Duration; import java.util.*; @@ -24,12 +23,12 @@ public class CacheProviderDelegate implements CacheProvider { private final CacheProvider cacheProvider; - public CacheProviderDelegate(CacheProperties properties, CacheProvider cacheProvider, Environment environment) { + public CacheProviderDelegate(CacheProperties properties, CacheProvider cacheProvider) { this.cacheProvider = cacheProvider; if (properties.isAppendPrefix()) { String prefix = properties.getPrefix(); if (StringUtils.isBlank(prefix)) { - prefix = ApplicationName.get(environment); + prefix = ApplicationName.get(); } this.prefixWithDelimiter = prefix + properties.getDelimiter(); } else { @@ -37,6 +36,11 @@ public class CacheProviderDelegate implements CacheProvider { } } + @Override + public boolean isExpired(String cacheKey) { + return getCacheProvider().isExpired(withKeyPrefix(cacheKey)); + } + @Override public void expire(String cacheKey, Duration expiration) { checkDuration(expiration); @@ -53,15 +57,6 @@ public class CacheProviderDelegate implements CacheProvider { return getCacheProvider().hasKey(withKeyPrefix(cacheKey)); } - @Override - public void del(List cacheKeys) { - if (CollectionUtils.isEmpty(cacheKeys)) { - return; - } - List keysWithPrefix = StreamUtils.toList(cacheKeys, this::withKeyPrefix); - getCacheProvider().del(keysWithPrefix); - } - @Override public Set keys(String pattern, long limit) { Set keys = getCacheProvider().keys(withKeyPrefix(pattern), limit); @@ -69,46 +64,17 @@ public class CacheProviderDelegate implements CacheProvider { } @Override - public T get(String cacheKey, Class valueType) { - return getCacheProvider().get(withKeyPrefix(cacheKey), valueType); - } - - @Override - public Map multiGet(Collection cacheKeys, Class valueType, boolean discardIfValueIsNull) { + public void del(List cacheKeys) { if (CollectionUtils.isEmpty(cacheKeys)) { - return Collections.emptyMap(); + return; } List keysWithPrefix = StreamUtils.toList(cacheKeys, this::withKeyPrefix); - Map cachedDate = getCacheProvider().multiGet(keysWithPrefix, valueType, discardIfValueIsNull); - Map result = Maps.newHashMapWithExpectedSize(keysWithPrefix.size()); - // 这里不能用 Stream toMap, toMap 不允许 value 是 null - if (MapUtils.isEmpty(cachedDate)) { - if (discardIfValueIsNull) { - result = Collections.emptyMap(); - } else { - for (String cacheKey : keysWithPrefix) { - result.put(removeKeyPrefix(cacheKey), null); - } - } - return result; - } else { - if (discardIfValueIsNull) { - // 值为 null 的key 在实现类获取时已经被丢弃,直接遍历 put 即可 - for (Entry cacheEntry : cachedDate.entrySet()) { - result.put(removeKeyPrefix(cacheEntry.getKey()), cacheEntry.getValue()); - } - } else { - for (String cacheKey : keysWithPrefix) { - result.put(removeKeyPrefix(cacheKey), cachedDate.get(cacheKey)); - } - } - } - return result; + getCacheProvider().del(keysWithPrefix); } @Override - public List getList(String cacheKey, Class valueType) { - return getCacheProvider().getList(withKeyPrefix(cacheKey), valueType); + public T get(String cacheKey, Class valueType) { + return getCacheProvider().get(withKeyPrefix(cacheKey), valueType); } @Override @@ -131,8 +97,27 @@ public class CacheProviderDelegate implements CacheProvider { } @Override - public boolean isExpired(String cacheKey) { - return getCacheProvider().isExpired(withKeyPrefix(cacheKey)); + public Map multiGet(Collection cacheKeys, Class valueType, boolean discardIfValueIsNull) { + if (CollectionUtils.isEmpty(cacheKeys)) { + return Collections.emptyMap(); + } + List keysWithPrefix = StreamUtils.toList(cacheKeys, this::withKeyPrefix); + Map dataWithPrefixedKey = getCacheProvider().multiGet(keysWithPrefix, valueType, discardIfValueIsNull); + if (MapUtils.isEmpty(dataWithPrefixedKey)) { + return Collections.emptyMap(); + } else { + Map result = Maps.newHashMapWithExpectedSize(dataWithPrefixedKey.size()); + // 这里不能用 Stream toMap, toMap 不允许 value 是 null + for (Entry cacheEntry : dataWithPrefixedKey.entrySet()) { + result.put(removeKeyPrefix(cacheEntry.getKey()), cacheEntry.getValue()); + } + return result; + } + } + + @Override + public List getList(String cacheKey, Class valueType) { + return getCacheProvider().getList(withKeyPrefix(cacheKey), valueType); } public CacheProvider getCacheProvider() { diff --git a/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/redis/RedisCacheProvider.java b/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/redis/RedisCacheProvider.java index b426dbc..4296b01 100644 --- a/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/redis/RedisCacheProvider.java +++ b/starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/redis/RedisCacheProvider.java @@ -7,10 +7,7 @@ import com.schbrain.framework.autoconfigure.cache.exception.CacheException; import com.schbrain.framework.autoconfigure.cache.provider.CacheProvider; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.data.redis.core.Cursor; -import org.springframework.data.redis.core.RedisCallback; -import org.springframework.data.redis.core.ScanOptions; -import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.core.*; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.util.CollectionUtils; @@ -34,6 +31,14 @@ public class RedisCacheProvider implements CacheProvider { this.redisTemplate = redisTemplate; } + /** + * 查询key是否过期 + */ + @Override + public boolean isExpired(String cacheKey) { + return !hasKey(cacheKey); + } + /** * 指定缓存失效时间 */ @@ -62,17 +67,6 @@ public class RedisCacheProvider implements CacheProvider { return Boolean.TRUE.equals(redisTemplate.hasKey(cacheKey)); } - /** - * 删除缓存 - */ - @Override - public void del(List cacheKeys) { - if (CollectionUtils.isEmpty(cacheKeys)) { - return; - } - redisTemplate.delete(cacheKeys); - } - /** * 模糊搜索 key */ @@ -92,35 +86,22 @@ public class RedisCacheProvider implements CacheProvider { } /** - * 缓存获取 + * 删除缓存 */ @Override - public T get(String cacheKey, Class type) { - return JacksonUtils.getObjectFromJson(getValueFromRedis(cacheKey), type); - } - - @Override - public Map multiGet(Collection cacheKeys, Class type, boolean discardIfValueIsNull) { - Map result = Maps.newHashMapWithExpectedSize(cacheKeys.size()); - Iterables.partition(cacheKeys, DEFAULT_BATCH_SIZE).forEach(subKeys -> { - List valueList = Objects.requireNonNull(redisTemplate.opsForValue().multiGet(subKeys)); - for (int i = 0; i < subKeys.size(); i++) { - T rawValue = JacksonUtils.getObjectFromJson(valueList.get(i), type); - if (discardIfValueIsNull && rawValue == null) { - continue; - } - result.put(subKeys.get(i), rawValue); - } - }); - return result; + public void del(List cacheKeys) { + if (CollectionUtils.isEmpty(cacheKeys)) { + return; + } + redisTemplate.delete(cacheKeys); } /** - * list 缓存获取 + * 缓存获取 */ @Override - public List getList(String cacheKey, Class type) { - return JacksonUtils.getListFromJson(getValueFromRedis(cacheKey), type); + public T get(String cacheKey, Class type) { + return JacksonUtils.getObjectFromJson(getValueFromRedis(cacheKey), type); } /** @@ -140,19 +121,36 @@ public class RedisCacheProvider implements CacheProvider { byteMap.put(key.getBytes(StandardCharsets.UTF_8), JacksonUtils.writeObjectAsBytes(data.get(key))); } connection.mSet(byteMap); + long expirationMillis = expiration.toMillis(); for (byte[] rawKey : byteMap.keySet()) { - connection.pExpire(rawKey, expiration.toMillis()); + connection.pExpire(rawKey, expirationMillis); } return null; })); } + @Override + public Map multiGet(Collection cacheKeys, Class type, boolean discardIfValueIsNull) { + Map result = Maps.newHashMapWithExpectedSize(cacheKeys.size()); + Iterables.partition(cacheKeys, DEFAULT_BATCH_SIZE).forEach(subKeys -> { + List valueList = Objects.requireNonNull(redisTemplate.opsForValue().multiGet(subKeys)); + for (int i = 0; i < subKeys.size(); i++) { + T rawValue = JacksonUtils.getObjectFromJson(valueList.get(i), type); + if (discardIfValueIsNull && rawValue == null) { + continue; + } + result.put(subKeys.get(i), rawValue); + } + }); + return result; + } + /** - * 查询key是否过期 + * list 缓存获取 */ @Override - public boolean isExpired(String cacheKey) { - return !hasKey(cacheKey); + public List getList(String cacheKey, Class type) { + return JacksonUtils.getListFromJson(getValueFromRedis(cacheKey), type); } private String getValueFromRedis(String cacheKey) { diff --git a/starters/logger-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/logger/listener/LoggerConfigLoadedEventListener.java b/starters/logger-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/logger/listener/LoggerConfigLoadedEventListener.java index 797059c..619317b 100644 --- a/starters/logger-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/logger/listener/LoggerConfigLoadedEventListener.java +++ b/starters/logger-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/logger/listener/LoggerConfigLoadedEventListener.java @@ -12,6 +12,9 @@ import com.schbrain.framework.autoconfigure.apollo.event.ConfigLoadedEvent; import com.schbrain.framework.autoconfigure.apollo.event.listener.GenericConfigLoadedEventListener; import com.schbrain.framework.autoconfigure.logger.LoggerConfigurationInitializer; import com.schbrain.framework.autoconfigure.logger.properties.LoggerProperties; +import org.springframework.boot.context.logging.LoggingApplicationListener; +import org.springframework.boot.logging.LogFile; +import org.springframework.boot.logging.LoggingSystem; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.util.StringUtils; @@ -48,9 +51,9 @@ public class LoggerConfigLoadedEventListener extends GenericConfigLoadedEventLis } /** - * Add {@link org.springframework.boot.context.logging.LoggingApplicationListener#CONFIG_PROPERTY} property to SystemProperty + * Add {@link LoggingApplicationListener#CONFIG_PROPERTY} property to SystemProperty * - * @see org.springframework.boot.context.logging.LoggingApplicationListener#initializeSystem(ConfigurableEnvironment, org.springframework.boot.logging.LoggingSystem, org.springframework.boot.logging.LogFile) + * @see LoggingApplicationListener#initializeSystem(ConfigurableEnvironment, LoggingSystem, LogFile) */ @SuppressWarnings("JavadocReference") private void configLoggingFileLocation(ConfigurableEnvironment environment, String logConfigNamespace) { diff --git a/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/DataSourcePropertiesExtractorSupport.java b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/DataSourcePropertiesExtractorSupport.java index dc8c1a3..f056816 100644 --- a/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/DataSourcePropertiesExtractorSupport.java +++ b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/DataSourcePropertiesExtractorSupport.java @@ -19,13 +19,13 @@ public abstract class DataSourcePropertiesExtractorSupport implements DataSource return TypeUtils.isAssignable(supportedType, dataSource.getClass()); } - public abstract Class getSupportedType(); - @Override public Properties extract(DataSource dataSource, Map properties) throws SQLException { return extract(dataSource); } + protected abstract Class getSupportedType(); + protected abstract Properties extract(DataSource dataSource) throws SQLException; } \ No newline at end of file diff --git a/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/DruidDataSourcePropertiesExtractor.java b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/DruidDataSourcePropertiesExtractor.java index 783dd2d..e8ae099 100644 --- a/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/DruidDataSourcePropertiesExtractor.java +++ b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/DruidDataSourcePropertiesExtractor.java @@ -17,7 +17,7 @@ import java.util.Properties; public class DruidDataSourcePropertiesExtractor extends DataSourcePropertiesExtractorSupport { @Override - public Class getSupportedType() { + protected Class getSupportedType() { return DruidDataSource.class; } diff --git a/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/HikariDataSourcePropertiesExtractor.java b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/HikariDataSourcePropertiesExtractor.java index 1f6fc08..299f2c9 100644 --- a/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/HikariDataSourcePropertiesExtractor.java +++ b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/datasource/extractor/HikariDataSourcePropertiesExtractor.java @@ -15,7 +15,7 @@ import java.util.Properties; public class HikariDataSourcePropertiesExtractor extends DataSourcePropertiesExtractorSupport { @Override - public Class getSupportedType() { + protected Class getSupportedType() { return HikariDataSource.class; } diff --git a/starters/xxl-job-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/xxl/SchbrainXxlJobExecutor.java b/starters/xxl-job-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/xxl/SchbrainXxlJobExecutor.java deleted file mode 100644 index e2fb868..0000000 --- a/starters/xxl-job-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/xxl/SchbrainXxlJobExecutor.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.schbrain.framework.autoconfigure.xxl; - -import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; -import com.xxl.job.core.thread.*; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.util.ReflectionUtils; - -import java.lang.reflect.Field; - -/** - * @author liaozan - * @since 2022/4/18 - */ -@Slf4j -public class SchbrainXxlJobExecutor extends XxlJobSpringExecutor implements InitializingBean, DisposableBean { - - private Field executorRegistryThreadStopField; - - private Field jobLogFileCleanThreadStopField; - - private Field triggerCallbackThreadStopField; - - private volatile boolean started = false; - - public SchbrainXxlJobExecutor() { - try { - this.executorRegistryThreadStopField = ExecutorRegistryThread.class.getDeclaredField("toStop"); - ReflectionUtils.makeAccessible(executorRegistryThreadStopField); - } catch (Exception e) { - this.executorRegistryThreadStopField = null; - } - try { - this.triggerCallbackThreadStopField = TriggerCallbackThread.class.getDeclaredField("toStop"); - ReflectionUtils.makeAccessible(triggerCallbackThreadStopField); - } catch (Exception e) { - this.triggerCallbackThreadStopField = null; - } - try { - this.jobLogFileCleanThreadStopField = JobLogFileCleanThread.class.getDeclaredField("toStop"); - ReflectionUtils.makeAccessible(jobLogFileCleanThreadStopField); - } catch (Exception e) { - this.jobLogFileCleanThreadStopField = null; - } - } - - @Override - public void start() throws Exception { - afterPropertiesSet(); - } - - @Override - public void afterPropertiesSet() throws Exception { - if (started) { - return; - } - super.start(); - started = true; - log.info("Xxl-job started"); - } - - @Override - public void destroy() { - if (!started) { - return; - } - super.destroy(); - resetThreadsStatus(); - started = false; - log.info("Xxl-job destroyed"); - } - - /** - * Reset xxl-job related thread to make it support restartable - */ - private void resetThreadsStatus() { - ReflectionUtils.setField(executorRegistryThreadStopField, ExecutorRegistryThread.getInstance(), false); - ReflectionUtils.setField(triggerCallbackThreadStopField, TriggerCallbackThread.getInstance(), false); - ReflectionUtils.setField(jobLogFileCleanThreadStopField, JobLogFileCleanThread.getInstance(), false); - } - -} \ No newline at end of file diff --git a/starters/xxl-job-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/xxl/XxlJobAutoConfiguration.java b/starters/xxl-job-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/xxl/XxlJobAutoConfiguration.java index 874a13b..56af583 100644 --- a/starters/xxl-job-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/xxl/XxlJobAutoConfiguration.java +++ b/starters/xxl-job-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/xxl/XxlJobAutoConfiguration.java @@ -5,6 +5,7 @@ import com.schbrain.framework.autoconfigure.logger.properties.LoggerProperties; import com.schbrain.framework.autoconfigure.xxl.condition.XxlJobShouldAvailableCondition; import com.schbrain.framework.autoconfigure.xxl.properties.XxlJobProperties; import com.xxl.job.core.executor.XxlJobExecutor; +import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -22,10 +23,10 @@ import java.nio.file.Paths; @EnableConfigurationProperties(XxlJobProperties.class) public class XxlJobAutoConfiguration { - @Bean + @Bean(initMethod = "start", destroyMethod = "destroy") @ConditionalOnMissingBean(XxlJobExecutor.class) - public SchbrainXxlJobExecutor schbrainXxlJobSpringExecutor(XxlJobProperties xxlJobProperties, LoggerProperties loggingProperties) { - SchbrainXxlJobExecutor executor = new SchbrainXxlJobExecutor(); + public XxlJobSpringExecutor xxlJobSpringExecutor(XxlJobProperties xxlJobProperties, LoggerProperties loggingProperties) { + XxlJobSpringExecutor executor = new XxlJobSpringExecutor(); executor.setAdminAddresses(xxlJobProperties.getAdminAddresses()); executor.setIp(xxlJobProperties.getIp()); executor.setPort(xxlJobProperties.getPort()); diff --git a/support/schbrain-base-dao/src/main/java/com/schbrain/framework/dao/BaseDao.java b/support/schbrain-base-dao/src/main/java/com/schbrain/framework/dao/BaseDao.java index 9b046ac..7620bb9 100644 --- a/support/schbrain-base-dao/src/main/java/com/schbrain/framework/dao/BaseDao.java +++ b/support/schbrain-base-dao/src/main/java/com/schbrain/framework/dao/BaseDao.java @@ -26,7 +26,7 @@ public interface BaseDao { * 批量插入领域对象 * * @param objList 待插入领域对象列表 - * @param fields 插入时指定的领域对象属性列表,如果为空表示对象的所有属性 + * @param fields 插入时指定的领域对象属性列表,如果为空表示对象的所有属性 * @return 影响行数 */ Integer addList(List objList, String... fields); @@ -50,11 +50,11 @@ public interface BaseDao { /** * 分页获取列表 * - * @param pageNum 当前页码 - * @param pageSize 当前页记录数 - * @param whereClause where关键词后的条件语句 + * @param pageNum 当前页码 + * @param pageSize 当前页记录数 + * @param whereClause where关键词后的条件语句 * @param orderByClause order by关键词后的排序语句,注意:语句中不支持参数 - * @param objs where关键词后的条件语句中参数对应的值 + * @param objs where关键词后的条件语句中参数对应的值 * @return page对象,包含记录及分页信息 */ Page pageByCondition(int pageNum, int pageSize, String whereClause, String orderByClause, Object... objs); -- GitLab