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 a174c21327e4cec70c47a2c5f3eb50161c948d42..78cc1bd9ea67dfc143bd915b336cbbe43fbcbb44 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 d658f76bdf5abf70a8fec1e50624663aa8f383c4..88a6284efe88e692a723eab57cbc7c63d9883f98 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 2ac7054e3749f2b6439effc6a1dead71434ffc50..8388c493521b19de8b6c23619c96804ea97658de 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 2333b66db004bc3499b581e801092f564db2feba..5c1a632b46484e36d122fdcc421442b986082f07 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 a8efd56c4d00f9524f41060fd09b4d2bf85ec0b2..9e8ea5df272a231f6727056b2e116298f49b3522 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 933c8b726193c949999a40caa247644d1a0adc1e..e0cdd8705883454a0ffd4d21aaffef8adbe9bc26 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 c7dd6e4dfe61f47217214cc566ce635f5ac5dd01..5771cd605827b682cc1ff0bc584f3df11005457a 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 1410be9240dd6716dcaabb3b8d1ee9300d4d2cf2..da716b2ec2949e6f613c9b9e57a91f08a4515fcb 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 dcdb11f593973f8dafd41c3a709489f37e71f2cf..2f18cd8ab8ed28f2fc4c3d0420d7873469d4e955 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 21892d172b8c23c60493d66d70ddd41261c3ffb6..592fb93abd45d2b4303183568449ccbaf95cddef 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 759fcd74b8a6a16dfb9f7f33cc56f63588a3a14b..82cf29819efec3f768fe3340551d6606d1d12336 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 2e018d04301f2126214ff1cc9ea39a1f8bf60fec..9214303457fef6b8ea66486b487b0b1e1873584c 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 0ee968454cefd120cbd3d6548ac0b4f5712a5633..7155a8cca9c66e5be678c7eff29fbbb31b3ce0c2 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 678339e12b184f92466306e325b10d5047651224..62e5ec6f9da4a0869f90402fd4b126b2827f1f3d 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 0a45535c4c86a0dd791a77c8aa74fcf5f4ecd01a..c9064c2d4c11c1fcd4b3701006f95d9cc7fdb878 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 aa79e6787a622a1b66eef25795ae15704f311b8c..b625f77fc01254fee82f4553489a759889cb6278 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 fc1838fcc8cef4a820c7705cf0f4744a99e066fc..6e2223a5a29b099be79dc633cc2077c17f115f1e 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 6056e849f5ddcb3dd450c4f42608b09b7750d894..72540ee55c6f21e3b902dce98dca723318e60c94 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 ab9225676f9be76f67f4b6385b5d7156b6c2f992..414c67e1ebac701867dedd569e4ef386859b3d61 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 70337f4da4e08476bac3b7cddce970b37e52dbe1..fbb95b7c8a6d6987e507b890d9d56161a8a389aa 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 0405ffedad4adab784676fbc7606e1bd558f956e..f2d5688d21982ad6fed5e402ad953235f94b46c0 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 b426dbc81c6ca202561052cf5627d1fe02a87849..4296b0126d9dd008343e6522354d8da7ce2d5bbe 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 797059c9a861033dec4cd22e5a90cea5268bf51a..619317b7619d851c42266ceb203761a82b3ce511 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 dc8c1a3722ca7f38743dee62af7d428984fbee9a..f056816646c85020ce0b40b992d32cdc68f9040e 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 783dd2d472a2a30be31b743c03c4c83fc775a2c8..e8ae099d768be0f6d0ae46562d84e99bf9a8d992 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 1f6fc081b2ae94622e47228f41588f6ff0bef60d..299f2c935c8e3fa20aba319a02b3b51c8f6dd400 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 e2fb868267d1bf13e2a6ed29b7bd507a2a6507f5..0000000000000000000000000000000000000000 --- 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 874a13b17337a9ee19e2b6c9a22c4851eaaa3555..56af58318d3940f924f2ff62420b7d44412a93de 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 9b046ac3e7852d8c46d323a1c3aa0a8944fe8bf9..7620bb9d2a87f1ad67ee58b7edd61bf5cfd0c2ba 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);