From 02ab5d20160b7fc3126486bc23fa51ced6d60c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=B6=9B?= Date: Wed, 21 Feb 2024 22:24:31 +0800 Subject: [PATCH 01/11] fix feign hc5 UT005023 error java.lang.NoSuchMethodError: 'long org.apache.hc.core5.pool.PoolEntry.getCreated --- opensabre-base-dependencies/pom.xml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/opensabre-base-dependencies/pom.xml b/opensabre-base-dependencies/pom.xml index bc473c1..f4b6e3f 100644 --- a/opensabre-base-dependencies/pom.xml +++ b/opensabre-base-dependencies/pom.xml @@ -48,7 +48,7 @@ 5.9.1 5.3.31 2.7.18 - 5.2.1 + 5.2.3 @@ -106,6 +106,11 @@ ${feign-interceptors} + + org.apache.httpcomponents.core5 + httpcore5 + ${httpclient5.version} + org.apache.httpcomponents.client5 httpclient5 From e6fc69b34b9eeeef5f94e320c0b824d35b309d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=B6=9B?= Date: Mon, 26 Feb 2024 23:04:42 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E5=8D=87=E7=BA=A7springboot3.2.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- opensabre-base-dependencies/pom.xml | 51 +++++++++++-------- opensabre-starter-boot/pom.xml | 6 +-- .../boot/config/OpensabreSwaggerConfig.java | 2 +- ...ensabreSensitiveDesensitizerProcessor.java | 2 +- .../event/OpensabreStartedEventHandler.java | 2 +- .../boot/rest/MappingInfoHandler.java | 2 +- .../desensitizer/RegxLogBackDesensitizer.java | 2 +- .../src/main/resources/bootstrap.properties | 3 +- .../src/main/resources/logback-spring.xml | 9 ++-- .../RegxLogBackDesensitizerTest.java | 2 +- .../src/test/resources/application.yml | 7 +-- .../src/main/resources/opensabre-register.yml | 2 +- opensabre-starter-rpc/pom.xml | 4 +- .../interceptor/FeignHeaderInterceptor.java | 2 +- opensabre-web/pom.xml | 4 +- .../web/interceptor/UserInterceptor.java | 5 +- .../web/rest/RestResponseBodyAdvice.java | 2 +- .../common/web/validator/EnumString.java | 5 +- .../web/validator/EnumStringValidator.java | 4 +- .../common/web/validator/Mobile.java | 4 +- .../common/web/validator/MobileValidator.java | 4 +- pom.xml | 2 +- 22 files changed, 67 insertions(+), 59 deletions(-) diff --git a/opensabre-base-dependencies/pom.xml b/opensabre-base-dependencies/pom.xml index f4b6e3f..149c408 100644 --- a/opensabre-base-dependencies/pom.xml +++ b/opensabre-base-dependencies/pom.xml @@ -18,36 +18,30 @@ UTF-8 UTF-8 - 11 - 11 + 17 + 17 1.18.24 2.7.5 1.4.13 + 3.11.0 - 2.7.18 - 2021.0.9 + 3.2.3 + 2023.0.0 2021.0.5.0 - 2.7.18 2.7.5 - 1.6.12 - 2.2.4 + 2.3.0 + 2.2.20 8.0.31 - 3.1.0 - 3.5.2 - 2.0.7 - 2.11.1 - 3.12.0 + 6.0.0 + 3.5.5 + 3.0.3 5.8.18 - 5.3.31 1.1.2 31.1-jre - 2.13.5 - 2.13.5 3.0.5 5.9.1 5.3.31 - 2.7.18 5.2.3 @@ -94,9 +88,9 @@ - javax.servlet - javax.servlet-api - ${javax.servlet-api.version} + jakarta.servlet + jakarta.servlet-api + ${jakarta.servlet-api.version} provided @@ -119,7 +113,7 @@ org.springdoc - springdoc-openapi-ui + springdoc-openapi-starter-webmvc-ui ${springdoc-openapi-ui.version} @@ -227,6 +221,14 @@ + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + true + + org.springframework.boot @@ -273,5 +275,14 @@ + + + org.apache.maven.plugins + maven-compiler-plugin + + --enable-preview + + + \ No newline at end of file diff --git a/opensabre-starter-boot/pom.xml b/opensabre-starter-boot/pom.xml index a58f594..0d3e296 100644 --- a/opensabre-starter-boot/pom.xml +++ b/opensabre-starter-boot/pom.xml @@ -48,8 +48,8 @@ - org.springframework.cloud - spring-cloud-starter-sleuth + io.micrometer + micrometer-tracing-bridge-otel @@ -64,7 +64,7 @@ org.springdoc - springdoc-openapi-ui + springdoc-openapi-starter-webmvc-ui diff --git a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/config/OpensabreSwaggerConfig.java b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/config/OpensabreSwaggerConfig.java index 757e10f..d98ab5e 100644 --- a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/config/OpensabreSwaggerConfig.java +++ b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/config/OpensabreSwaggerConfig.java @@ -10,7 +10,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import javax.annotation.Resource; +import jakarta.annotation.Resource; /** * Swagger配置类 diff --git a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/event/OpensabreSensitiveDesensitizerProcessor.java b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/event/OpensabreSensitiveDesensitizerProcessor.java index 59a85c4..d14901e 100644 --- a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/event/OpensabreSensitiveDesensitizerProcessor.java +++ b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/event/OpensabreSensitiveDesensitizerProcessor.java @@ -6,7 +6,7 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; -import javax.annotation.Resource; +import jakarta.annotation.Resource; @Slf4j public class OpensabreSensitiveDesensitizerProcessor implements BeanPostProcessor { diff --git a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/event/OpensabreStartedEventHandler.java b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/event/OpensabreStartedEventHandler.java index b93d0ac..2fabfdf 100644 --- a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/event/OpensabreStartedEventHandler.java +++ b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/event/OpensabreStartedEventHandler.java @@ -6,7 +6,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationListener; -import javax.annotation.Resource; +import jakarta.annotation.Resource; /** * springboot应用启动完成后,发送Rest注册事件 diff --git a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/rest/MappingInfoHandler.java b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/rest/MappingInfoHandler.java index 3c7b1b7..c80b257 100644 --- a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/rest/MappingInfoHandler.java +++ b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/rest/MappingInfoHandler.java @@ -6,7 +6,7 @@ import org.springframework.web.servlet.mvc.method.RequestMappingInfo; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; -import javax.annotation.Resource; +import jakarta.annotation.Resource; import java.util.HashSet; import java.util.Map; import java.util.Set; diff --git a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/sensitive/log/desensitizer/RegxLogBackDesensitizer.java b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/sensitive/log/desensitizer/RegxLogBackDesensitizer.java index feb822e..f07ed42 100644 --- a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/sensitive/log/desensitizer/RegxLogBackDesensitizer.java +++ b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/sensitive/log/desensitizer/RegxLogBackDesensitizer.java @@ -6,7 +6,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.Map; diff --git a/opensabre-starter-boot/src/main/resources/bootstrap.properties b/opensabre-starter-boot/src/main/resources/bootstrap.properties index 74dc6cc..a9753e1 100644 --- a/opensabre-starter-boot/src/main/resources/bootstrap.properties +++ b/opensabre-starter-boot/src/main/resources/bootstrap.properties @@ -1,4 +1,5 @@ #==============日志===============# logging.level.io.github.opensabre=info logging.logback.rollingpolicy.max-file-size=1GB -logging.file.path=logs/ \ No newline at end of file +logging.file.path=logs +logging.pattern.level=%5p [${spring.application.name},%X{traceId:-},%X{spanId:-}] \ No newline at end of file diff --git a/opensabre-starter-boot/src/main/resources/logback-spring.xml b/opensabre-starter-boot/src/main/resources/logback-spring.xml index 631dfca..8acd1a4 100644 --- a/opensabre-starter-boot/src/main/resources/logback-spring.xml +++ b/opensabre-starter-boot/src/main/resources/logback-spring.xml @@ -47,13 +47,12 @@ UTF-8 - + ${log.path}/opensabre-%d{yyyy-MM-dd}.%i.log - - 100MB - - + + 100MB + 15 diff --git a/opensabre-starter-boot/src/test/java/io/github/opensabre/boot/sensitive/log/desensitizer/RegxLogBackDesensitizerTest.java b/opensabre-starter-boot/src/test/java/io/github/opensabre/boot/sensitive/log/desensitizer/RegxLogBackDesensitizerTest.java index d574a09..a6364ca 100644 --- a/opensabre-starter-boot/src/test/java/io/github/opensabre/boot/sensitive/log/desensitizer/RegxLogBackDesensitizerTest.java +++ b/opensabre-starter-boot/src/test/java/io/github/opensabre/boot/sensitive/log/desensitizer/RegxLogBackDesensitizerTest.java @@ -7,7 +7,7 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; -import javax.annotation.Resource; +import jakarta.annotation.Resource; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/opensabre-starter-boot/src/test/resources/application.yml b/opensabre-starter-boot/src/test/resources/application.yml index ff190b0..775493b 100644 --- a/opensabre-starter-boot/src/test/resources/application.yml +++ b/opensabre-starter-boot/src/test/resources/application.yml @@ -3,11 +3,6 @@ spring: bus: trace: enabled: true - sleuth: - sampler: - probability: 1.0 - mvc: - throw-exception-if-no-handler-found: true format: date-time: yyyy-MM-dd HH:mm:ss date: yyyy-MM-dd @@ -44,5 +39,5 @@ logging: rollingpolicy: max-file-size: 1GB file: - path: logs/ + path: logs config: classpath:logback-spring.xml diff --git a/opensabre-starter-register/src/main/resources/opensabre-register.yml b/opensabre-starter-register/src/main/resources/opensabre-register.yml index 3e3111d..be69f6e 100644 --- a/opensabre-starter-register/src/main/resources/opensabre-register.yml +++ b/opensabre-starter-register/src/main/resources/opensabre-register.yml @@ -4,6 +4,6 @@ spring: discovery: server-addr: ${REGISTER_HOST:localhost}:${REGISTER_PORT:8848} watch: - enabled: true + enabled: false enabled: true cluster-name: CLUSTER-${CLOUD_AZ:LOCAL} # 取环境变量AZ做为部分集群名:CLUSTER-SH,无环境变量默认为CLUSTER-LOCAL代表本地开发实例 \ No newline at end of file diff --git a/opensabre-starter-rpc/pom.xml b/opensabre-starter-rpc/pom.xml index 209c967..d8d9439 100644 --- a/opensabre-starter-rpc/pom.xml +++ b/opensabre-starter-rpc/pom.xml @@ -67,8 +67,8 @@ - javax.servlet - javax.servlet-api + jakarta.servlet + jakarta.servlet-api provided diff --git a/opensabre-starter-rpc/src/main/java/io/github/opensabre/rpc/openfeign/interceptor/FeignHeaderInterceptor.java b/opensabre-starter-rpc/src/main/java/io/github/opensabre/rpc/openfeign/interceptor/FeignHeaderInterceptor.java index 191c702..c37ef3a 100644 --- a/opensabre-starter-rpc/src/main/java/io/github/opensabre/rpc/openfeign/interceptor/FeignHeaderInterceptor.java +++ b/opensabre-starter-rpc/src/main/java/io/github/opensabre/rpc/openfeign/interceptor/FeignHeaderInterceptor.java @@ -7,7 +7,7 @@ import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; import java.util.Enumeration; import java.util.Map; diff --git a/opensabre-web/pom.xml b/opensabre-web/pom.xml index 21985fd..30a297f 100644 --- a/opensabre-web/pom.xml +++ b/opensabre-web/pom.xml @@ -121,8 +121,8 @@ - javax.servlet - javax.servlet-api + jakarta.servlet + jakarta.servlet-api provided diff --git a/opensabre-web/src/main/java/io/github/opensabre/common/web/interceptor/UserInterceptor.java b/opensabre-web/src/main/java/io/github/opensabre/common/web/interceptor/UserInterceptor.java index b3cb1ac..bdba6c1 100644 --- a/opensabre-web/src/main/java/io/github/opensabre/common/web/interceptor/UserInterceptor.java +++ b/opensabre-web/src/main/java/io/github/opensabre/common/web/interceptor/UserInterceptor.java @@ -2,12 +2,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.github.opensabre.common.core.util.UserContextHolder; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; import org.springframework.lang.Nullable; import org.springframework.web.servlet.HandlerInterceptor; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; + import java.util.Map; /** diff --git a/opensabre-web/src/main/java/io/github/opensabre/common/web/rest/RestResponseBodyAdvice.java b/opensabre-web/src/main/java/io/github/opensabre/common/web/rest/RestResponseBodyAdvice.java index e7d8490..7379d90 100644 --- a/opensabre-web/src/main/java/io/github/opensabre/common/web/rest/RestResponseBodyAdvice.java +++ b/opensabre-web/src/main/java/io/github/opensabre/common/web/rest/RestResponseBodyAdvice.java @@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; /** * Rest统一返回报文封装,在rest方法返回后送给客户端前执行 diff --git a/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/EnumString.java b/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/EnumString.java index bc44b9e..9cb9f88 100644 --- a/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/EnumString.java +++ b/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/EnumString.java @@ -1,7 +1,8 @@ package io.github.opensabre.common.web.validator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; + import java.lang.annotation.Documented; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; diff --git a/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/EnumStringValidator.java b/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/EnumStringValidator.java index 02be74c..7ca94b5 100644 --- a/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/EnumStringValidator.java +++ b/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/EnumStringValidator.java @@ -2,8 +2,8 @@ import org.apache.commons.lang3.StringUtils; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; import java.util.Arrays; import java.util.List; diff --git a/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/Mobile.java b/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/Mobile.java index 0581e92..c3ad4e1 100644 --- a/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/Mobile.java +++ b/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/Mobile.java @@ -1,7 +1,7 @@ package io.github.opensabre.common.web.validator; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; diff --git a/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/MobileValidator.java b/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/MobileValidator.java index acad154..b59ea03 100644 --- a/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/MobileValidator.java +++ b/opensabre-web/src/main/java/io/github/opensabre/common/web/validator/MobileValidator.java @@ -2,8 +2,8 @@ import org.apache.commons.lang3.StringUtils; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; import java.util.regex.Pattern; /** diff --git a/pom.xml b/pom.xml index 639aa84..1694ec4 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ 1.6.8 2.22.2 - 0.0.9 + 0.1.0 From af7e0392150606e9b477f3cb13054344e50d5550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=B6=9B?= Date: Tue, 27 Feb 2024 23:44:41 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E6=8E=A5=E5=85=A5knife4j=20doc=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- opensabre-base-dependencies/pom.xml | 12 ++++++------ opensabre-starter-boot/pom.xml | 4 ++-- .../src/main/resources/opensabre-boot.properties | 3 +++ opensabre-web/pom.xml | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/opensabre-base-dependencies/pom.xml b/opensabre-base-dependencies/pom.xml index 149c408..83a2e2b 100644 --- a/opensabre-base-dependencies/pom.xml +++ b/opensabre-base-dependencies/pom.xml @@ -29,8 +29,8 @@ 2023.0.0 2021.0.5.0 2.7.5 - 2.3.0 - 2.2.20 + 4.4.0 + 2.2.19 8.0.31 6.0.0 3.5.5 @@ -112,9 +112,9 @@ - org.springdoc - springdoc-openapi-starter-webmvc-ui - ${springdoc-openapi-ui.version} + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + ${knife4j-openapi3.version} @@ -193,7 +193,7 @@ io.swagger.core.v3 - swagger-annotations + swagger-annotations-jakarta ${swagger-annotations.version} diff --git a/opensabre-starter-boot/pom.xml b/opensabre-starter-boot/pom.xml index 0d3e296..be34399 100644 --- a/opensabre-starter-boot/pom.xml +++ b/opensabre-starter-boot/pom.xml @@ -63,8 +63,8 @@ - org.springdoc - springdoc-openapi-starter-webmvc-ui + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter diff --git a/opensabre-starter-boot/src/main/resources/opensabre-boot.properties b/opensabre-starter-boot/src/main/resources/opensabre-boot.properties index 0d225a9..1cf8e7c 100644 --- a/opensabre-starter-boot/src/main/resources/opensabre-boot.properties +++ b/opensabre-starter-boot/src/main/resources/opensabre-boot.properties @@ -37,3 +37,6 @@ opensabre.rest.swagger.licenseUrl=https://github.com/opensabre/opensabre-framewo opensabre.rest.swagger.licenseName=Apache 2.0 opensabre.rest.swagger.wikiUrl=https://opensabre.github.io/docs opensabre.rest.swagger.wikiDocumentation=Opensabre Wiki Documentation +# knife4j的增强配置 +knife4j.enable=true +knife4j.setting.language=zh_cn diff --git a/opensabre-web/pom.xml b/opensabre-web/pom.xml index 30a297f..4e40c6a 100644 --- a/opensabre-web/pom.xml +++ b/opensabre-web/pom.xml @@ -67,7 +67,7 @@ io.swagger.core.v3 - swagger-annotations + swagger-annotations-jakarta From c2a729981eefadc878f38fca447e654c1eb7088b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=B6=9B?= Date: Tue, 5 Mar 2024 22:52:22 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E5=8D=87=E7=BA=A7springcloud=20alibaba?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- opensabre-base-dependencies/pom.xml | 4 +++- .../boot/config/OpensabreSensitiveConfig.java | 1 - .../src/main/resources/bootstrap.properties | 5 ----- .../src/main/resources/bootstrap.yaml | 11 ++++++++++ .../main/resources/opensabre-cache.properties | 22 ++++++++++--------- .../common/core/entity/vo/Result.java | 6 ++--- .../web/rest/RestResponseBodyAdvice.java | 5 +++-- 7 files changed, 32 insertions(+), 22 deletions(-) delete mode 100644 opensabre-starter-boot/src/main/resources/bootstrap.properties create mode 100644 opensabre-starter-boot/src/main/resources/bootstrap.yaml diff --git a/opensabre-base-dependencies/pom.xml b/opensabre-base-dependencies/pom.xml index 83a2e2b..316dbe3 100644 --- a/opensabre-base-dependencies/pom.xml +++ b/opensabre-base-dependencies/pom.xml @@ -27,7 +27,7 @@ 3.2.3 2023.0.0 - 2021.0.5.0 + 2023.0.0.0-RC1 2.7.5 4.4.0 2.2.19 @@ -281,6 +281,8 @@ maven-compiler-plugin --enable-preview + 16 + 16 diff --git a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/config/OpensabreSensitiveConfig.java b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/config/OpensabreSensitiveConfig.java index 3abbf6e..c7291c0 100644 --- a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/config/OpensabreSensitiveConfig.java +++ b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/config/OpensabreSensitiveConfig.java @@ -28,7 +28,6 @@ public BeanFactoryPostProcessor beanFactoryPostProcessor() { } @Bean - @ConditionalOnMissingBean public LogBackDesensitizer regxLogBackDesensitizer() { return new RegxLogBackDesensitizer(); } diff --git a/opensabre-starter-boot/src/main/resources/bootstrap.properties b/opensabre-starter-boot/src/main/resources/bootstrap.properties deleted file mode 100644 index a9753e1..0000000 --- a/opensabre-starter-boot/src/main/resources/bootstrap.properties +++ /dev/null @@ -1,5 +0,0 @@ -#==============日志===============# -logging.level.io.github.opensabre=info -logging.logback.rollingpolicy.max-file-size=1GB -logging.file.path=logs -logging.pattern.level=%5p [${spring.application.name},%X{traceId:-},%X{spanId:-}] \ No newline at end of file diff --git a/opensabre-starter-boot/src/main/resources/bootstrap.yaml b/opensabre-starter-boot/src/main/resources/bootstrap.yaml new file mode 100644 index 0000000..6e0267e --- /dev/null +++ b/opensabre-starter-boot/src/main/resources/bootstrap.yaml @@ -0,0 +1,11 @@ +#==============日志===============# +logging: + level: + io.github.opensabre: info + logback: + rollingpolicy: + max-file-size: 1GB + file: + path: logs + pattern: + level: '%5p [${spring.application.name},%X{traceId:-},%X{spanId:-}]' \ No newline at end of file diff --git a/opensabre-starter-cache/src/main/resources/opensabre-cache.properties b/opensabre-starter-cache/src/main/resources/opensabre-cache.properties index eba395b..89a798d 100644 --- a/opensabre-starter-cache/src/main/resources/opensabre-cache.properties +++ b/opensabre-starter-cache/src/main/resources/opensabre-cache.properties @@ -1,24 +1,26 @@ #==============缓存===============# jetcache.statIntervalMinutes=10 jetcache.hidePackages=io.github.opensabre -# 短時本地緩存1分钟,主要用于要求时效较高的配置 +# 默认本地緩存5分钟 +jetcache.local.default.type=caffeine +jetcache.local.default.keyConvertor=jackson +jetcache.local.default.expireAfterWriteInMillis=300000 +jetcache.local.default.expireAfterAccessInMillis=180000 +# 長時本地緩存1小时,主要用于要求时效一般 jetcache.local.longTime.type=caffeine -jetcache.local.longTime.keyConvertor=fastjson +jetcache.local.longTime.keyConvertor=jackson jetcache.local.longTime.expireAfterWriteInMillis=3600000 jetcache.local.longTime.expireAfterAccessInMillis=1800000 +# 短時本地緩存1分钟,主要用于要求时效较高的配置 jetcache.local.shortTime.type=caffeine jetcache.local.shortTime.keyConvertor=jackson jetcache.local.shortTime.expireAfterWriteInMillis=60000 jetcache.local.shortTime.expireAfterAccessInMillis=40000 -# 長時本地緩存1小时,主要用于要求时效一般 -jetcache.local.default.type=caffeine -jetcache.local.default.keyConvertor=jackson -jetcache.local.default.expireAfterWriteInMillis=300000 -jetcache.local.default.expireAfterAccessInMillis=180000 + # 默认2小时的远程缓存 jetcache.remote.default.type=redis.lettuce jetcache.remote.default.expireAfterWriteInMillis=7200000 -jetcache.remote.default.keyConvertor=fastjson +jetcache.remote.default.keyConvertor=jackson jetcache.remote.default.valueEncoder=java jetcache.remote.default.valueDecoder=java jetcache.remote.default.poolConfig.minIdle=5 @@ -28,7 +30,7 @@ jetcache.remote.default.uri=redis://${REDIS_HOST:localhost}:${REDIS_PORT:6379} # 长时远程緩存12小时,主要用于要求时效要求一般的集中式缓存 jetcache.remote.longTime.type=redis.lettuce jetcache.remote.longTime.expireAfterWriteInMillis=43200000 -jetcache.remote.longTime.keyConvertor=fastjson +jetcache.remote.longTime.keyConvertor=jackson jetcache.remote.longTime.valueEncoder=java jetcache.remote.longTime.valueDecoder=java jetcache.remote.longTime.poolConfig.minIdle=5 @@ -38,7 +40,7 @@ jetcache.remote.longTime.uri=redis://${REDIS_HOST:localhost}:${REDIS_PORT:6379} # 短時远程緩存5分钟,主要用于要求时效较高的集中式缓存 jetcache.remote.shortTime.type=redis.lettuce jetcache.remote.shortTime.expireAfterWriteInMillis=300000 -jetcache.remote.shortTime.keyConvertor=fastjson +jetcache.remote.shortTime.keyConvertor=jackson jetcache.remote.shortTime.valueEncoder=java jetcache.remote.shortTime.valueDecoder=java jetcache.remote.shortTime.poolConfig.minIdle=5 diff --git a/opensabre-web/src/main/java/io/github/opensabre/common/core/entity/vo/Result.java b/opensabre-web/src/main/java/io/github/opensabre/common/core/entity/vo/Result.java index 0c1f200..67864e0 100644 --- a/opensabre-web/src/main/java/io/github/opensabre/common/core/entity/vo/Result.java +++ b/opensabre-web/src/main/java/io/github/opensabre/common/core/entity/vo/Result.java @@ -33,7 +33,7 @@ public class Result { /** * 统一报文中code代码,标明异常类型 */ - @Schema(title = "处理结果code", required = true) + @Schema(title = "处理结果code", requiredMode = Schema.RequiredMode.REQUIRED) private final String code; /** * 统一报文中提示信息 @@ -43,7 +43,7 @@ public class Result { /** * 统一报文中报文生成时间 */ - @Schema(title = "请求结果生成时间戳", required = true) + @Schema(title = "请求结果生成时间戳", requiredMode = Schema.RequiredMode.REQUIRED) @JsonFormat(pattern = DatePattern.UTC_MS_PATTERN) @JsonSerialize(using = LocalDateTimeSerializer.class) @JsonDeserialize(using = LocalDateTimeDeserializer.class) @@ -51,7 +51,7 @@ public class Result { /** * 统一报文中数据部分,支持泛型 */ - @Schema(title = "处理结果数据信息", required = true) + @Schema(title = "处理结果数据信息", requiredMode = Schema.RequiredMode.REQUIRED) @JsonInclude(JsonInclude.Include.NON_NULL) private T data; diff --git a/opensabre-web/src/main/java/io/github/opensabre/common/web/rest/RestResponseBodyAdvice.java b/opensabre-web/src/main/java/io/github/opensabre/common/web/rest/RestResponseBodyAdvice.java index 7379d90..132bce7 100644 --- a/opensabre-web/src/main/java/io/github/opensabre/common/web/rest/RestResponseBodyAdvice.java +++ b/opensabre-web/src/main/java/io/github/opensabre/common/web/rest/RestResponseBodyAdvice.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.github.opensabre.common.core.entity.vo.Result; +import jakarta.validation.constraints.NotNull; import lombok.SneakyThrows; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; @@ -16,7 +17,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; -import jakarta.validation.constraints.NotNull; +import java.util.Objects; /** * Rest统一返回报文封装,在rest方法返回后送给客户端前执行 @@ -71,7 +72,7 @@ public Object beforeBodyWrite(Object body, return body; } // 如果是String,将Result转为json string - if (body instanceof String) { + if (Objects.isNull(body) || body instanceof String) { return new ObjectMapper().writeValueAsString(Result.success(body)); } return Result.success(body); From ede8d4a9484de7fc3f82a51b33244cb43b98165d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=B6=9B?= Date: Wed, 6 Mar 2024 22:31:10 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E9=9D=99=E6=80=81=E8=B5=84=E6=BA=90=EF=BC=8C=E5=A4=84=E7=90=86?= =?UTF-8?q?404=E8=BF=94=E5=9B=9E=E6=8A=A5=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/opensabre-boot.properties | 2 +- .../opensabre/common/core/exception/SystemErrorType.java | 4 ++++ .../exception/DefaultGlobalExceptionHandlerAdvice.java | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/opensabre-starter-boot/src/main/resources/opensabre-boot.properties b/opensabre-starter-boot/src/main/resources/opensabre-boot.properties index 1cf8e7c..4aaa80c 100644 --- a/opensabre-starter-boot/src/main/resources/opensabre-boot.properties +++ b/opensabre-starter-boot/src/main/resources/opensabre-boot.properties @@ -1,5 +1,5 @@ #==============springboot相关配置===============# -spring.sleuth.sampler.probability=1 +spring.web.resources.add-mappings=false spring.mvc.format.date-time=yyyy-MM-dd HH:mm:ss spring.mvc.format.date=yyyy-MM-dd spring.servlet.multipart.max-request-size=2MB diff --git a/opensabre-web/src/main/java/io/github/opensabre/common/core/exception/SystemErrorType.java b/opensabre-web/src/main/java/io/github/opensabre/common/core/exception/SystemErrorType.java index eac3be5..a5f146e 100644 --- a/opensabre-web/src/main/java/io/github/opensabre/common/core/exception/SystemErrorType.java +++ b/opensabre-web/src/main/java/io/github/opensabre/common/core/exception/SystemErrorType.java @@ -15,6 +15,10 @@ public enum SystemErrorType implements ErrorType { * 系统繁忙,限流时 */ SYSTEM_BUSY("000001", "系统繁忙,请稍候再试"), + /** + * 未找到该资源 + */ + RESOURCE_NOT_FOUND("000404", "资源未找到"), /** * 网关转发时未找到该服务 */ diff --git a/opensabre-web/src/main/java/io/github/opensabre/common/web/exception/DefaultGlobalExceptionHandlerAdvice.java b/opensabre-web/src/main/java/io/github/opensabre/common/web/exception/DefaultGlobalExceptionHandlerAdvice.java index 882d648..a70f2e5 100644 --- a/opensabre-web/src/main/java/io/github/opensabre/common/web/exception/DefaultGlobalExceptionHandlerAdvice.java +++ b/opensabre-web/src/main/java/io/github/opensabre/common/web/exception/DefaultGlobalExceptionHandlerAdvice.java @@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import org.springframework.web.multipart.MultipartException; +import org.springframework.web.servlet.NoHandlerFoundException; /** * 默认全局异常处理类 @@ -56,6 +57,13 @@ public Result notSupportedMethodException(HttpRequestMethodNotSupportedException return Result.fail(SystemErrorType.METHOD_NOT_SUPPORTED); } + @ExceptionHandler(value = {NoHandlerFoundException.class}) + @ResponseStatus(HttpStatus.NOT_FOUND) + public Result noHandlerFoundException(NoHandlerFoundException ex) { + log.warn("No static resource exception:{}", ex.getMessage()); + return Result.fail(SystemErrorType.RESOURCE_NOT_FOUND, ex.getMessage()); + } + @ExceptionHandler(value = {HttpMediaTypeNotSupportedException.class}) @ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE) public Result notSupportedMethodException(HttpMediaTypeNotSupportedException ex) { From ec15ae553c42ce3646f035f6d16ac0252063518e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=B6=9B?= Date: Tue, 12 Mar 2024 23:12:45 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E8=A1=A5=E5=85=85model=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?swagger=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../opensabre/persistence/entity/form/BaseQueryForm.java | 2 ++ .../opensabre/persistence/entity/param/BaseParam.java | 3 +++ .../io/github/opensabre/persistence/entity/po/BasePo.java | 7 +++++++ .../io/github/opensabre/common/core/entity/vo/Result.java | 8 ++++---- .../github/opensabre/common/web/entity/form/BaseForm.java | 1 + .../io/github/opensabre/common/web/entity/vo/BaseVo.java | 2 ++ 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/entity/form/BaseQueryForm.java b/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/entity/form/BaseQueryForm.java index e0b128a..d4cbc36 100644 --- a/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/entity/form/BaseQueryForm.java +++ b/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/entity/form/BaseQueryForm.java @@ -15,10 +15,12 @@ public class BaseQueryForm

extends BaseForm { /** * 分页查询的参数,当前页数 */ + @Schema(title = "当前页数", description = "分页查询的参数,当前页数", requiredMode = Schema.RequiredMode.REQUIRED, defaultValue = "1") private long current = 1; /** * 分页查询的参数,当前页面每页显示的数量 */ + @Schema(title = "每页数量", description = "分页查询的参数,当前页面每页显示的数量", requiredMode = Schema.RequiredMode.REQUIRED, defaultValue = "10") private long size = 10; /** diff --git a/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/entity/param/BaseParam.java b/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/entity/param/BaseParam.java index 901630a..e506b43 100644 --- a/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/entity/param/BaseParam.java +++ b/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/entity/param/BaseParam.java @@ -1,5 +1,6 @@ package io.github.opensabre.persistence.entity.param; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.NoArgsConstructor; @@ -14,7 +15,9 @@ @Data @NoArgsConstructor public class BaseParam implements Serializable { + @Schema(title = "开始时间", description = "查询条件创建记录的开始时间", requiredMode = Schema.RequiredMode.REQUIRED, example="2020-05-06 12:23:23") private Date createdTimeStart; + @Schema(title = "结束时间", description = "查询条件创建记录的结束时间", requiredMode = Schema.RequiredMode.REQUIRED, example="2020-05-12 12:23:23") private Date createdTimeEnd; // public QueryWrapper build() { diff --git a/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/entity/po/BasePo.java b/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/entity/po/BasePo.java index 02b960c..cd4272d 100644 --- a/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/entity/po/BasePo.java +++ b/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/entity/po/BasePo.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableId; import io.github.opensabre.common.web.entity.convert.EntityModelConverter; import io.github.opensabre.common.web.entity.vo.BaseVo; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.NoArgsConstructor; @@ -16,18 +17,24 @@ @NoArgsConstructor public class BasePo implements Serializable { public final static String DEFAULT_USERNAME = "system"; + + @Schema(title = "主键", description = "存储数据记录的唯一ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "100001") @TableId(type = IdType.ASSIGN_ID) private String id; + @Schema(title = "创建人", description = "创建该数据记录人的唯一ID,默认为system", requiredMode = Schema.RequiredMode.REQUIRED, example = "admin") @TableField(fill = FieldFill.INSERT) private String createdBy; + @Schema(title = "创建时间", description = "创建该数据记录的时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2021-04-09 21:00:00") @TableField(fill = FieldFill.INSERT) private Date createdTime; + @Schema(title = "更新人", description = "更新该数据记录人的唯一ID,默认为system", requiredMode = Schema.RequiredMode.REQUIRED, example = "admin") @TableField(fill = FieldFill.INSERT_UPDATE) private String updatedBy; + @Schema(title = "更新时间", description = "更新该数据记录的时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2021-04-10 21:00:00") @TableField(fill = FieldFill.INSERT_UPDATE) private Date updatedTime; diff --git a/opensabre-web/src/main/java/io/github/opensabre/common/core/entity/vo/Result.java b/opensabre-web/src/main/java/io/github/opensabre/common/core/entity/vo/Result.java index 67864e0..1808491 100644 --- a/opensabre-web/src/main/java/io/github/opensabre/common/core/entity/vo/Result.java +++ b/opensabre-web/src/main/java/io/github/opensabre/common/core/entity/vo/Result.java @@ -33,17 +33,17 @@ public class Result { /** * 统一报文中code代码,标明异常类型 */ - @Schema(title = "处理结果code", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(title = "处理结果code", description = "处理结果,000000为成功", requiredMode = Schema.RequiredMode.REQUIRED, example="000000") private final String code; /** * 统一报文中提示信息 */ - @Schema(title = "处理结果描述信息") + @Schema(title = "处理结果描述信息", description = "对code的详细说明和描述", example = "成功") private final String mesg; /** * 统一报文中报文生成时间 */ - @Schema(title = "请求结果生成时间戳", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(title = "请求结果生成时间戳", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-01-01T20:30:00.123Z") @JsonFormat(pattern = DatePattern.UTC_MS_PATTERN) @JsonSerialize(using = LocalDateTimeSerializer.class) @JsonDeserialize(using = LocalDateTimeDeserializer.class) @@ -51,7 +51,7 @@ public class Result { /** * 统一报文中数据部分,支持泛型 */ - @Schema(title = "处理结果数据信息", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(title = "处理结果数据信息", description = "可能为字符串、数组、对象等", requiredMode = Schema.RequiredMode.REQUIRED, example = "上海市") @JsonInclude(JsonInclude.Include.NON_NULL) private T data; diff --git a/opensabre-web/src/main/java/io/github/opensabre/common/web/entity/form/BaseForm.java b/opensabre-web/src/main/java/io/github/opensabre/common/web/entity/form/BaseForm.java index 3df1365..2ebbb4f 100644 --- a/opensabre-web/src/main/java/io/github/opensabre/common/web/entity/form/BaseForm.java +++ b/opensabre-web/src/main/java/io/github/opensabre/common/web/entity/form/BaseForm.java @@ -12,6 +12,7 @@ public class BaseForm

implements Serializable { /** * 用户名 */ + @Schema(title = "用户名", description = "Form提交时操作人的用户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "admin") private String username; /** diff --git a/opensabre-web/src/main/java/io/github/opensabre/common/web/entity/vo/BaseVo.java b/opensabre-web/src/main/java/io/github/opensabre/common/web/entity/vo/BaseVo.java index a45f239..44047fd 100644 --- a/opensabre-web/src/main/java/io/github/opensabre/common/web/entity/vo/BaseVo.java +++ b/opensabre-web/src/main/java/io/github/opensabre/common/web/entity/vo/BaseVo.java @@ -1,5 +1,6 @@ package io.github.opensabre.common.web.entity.vo; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.NoArgsConstructor; @@ -14,5 +15,6 @@ public class BaseVo implements Serializable { /** * VO对象唯一id */ + @Schema(title = "对象唯一id", description = "对象唯一id", requiredMode = Schema.RequiredMode.REQUIRED) private String id; } \ No newline at end of file From 725db679e7b1fabc57b150543a7625cbc737826d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=B6=9B?= Date: Tue, 12 Mar 2024 23:13:45 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=8F=8A=E6=A1=86=E6=9E=B6=E7=89=88=E6=9C=AC=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=92=8Cbanner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../boot/config/OpensabreEnvConfig.java | 41 +++++++++++-------- .../boot/metadata/OpensabreCloud.java | 8 ++++ .../boot/metadata/OpensabreVersion.java | 8 ++++ .../src/main/resources/banner.txt | 2 +- .../opensabre/register/config/Metadata.java | 4 +- 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/config/OpensabreEnvConfig.java b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/config/OpensabreEnvConfig.java index 4e3406c..baf51e1 100644 --- a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/config/OpensabreEnvConfig.java +++ b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/config/OpensabreEnvConfig.java @@ -1,5 +1,7 @@ package io.github.opensabre.boot.config; +import cn.hutool.core.io.resource.NoResourceException; +import cn.hutool.setting.dialect.Props; import io.github.opensabre.boot.metadata.OpensabreCloud; import io.github.opensabre.boot.metadata.OpensabreVersion; import lombok.extern.slf4j.Slf4j; @@ -8,31 +10,21 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertiesPropertySource; import java.util.HashMap; +import static io.github.opensabre.boot.metadata.OpensabreCloud.OPENSABRE_CLOUD_AZ; +import static io.github.opensabre.boot.metadata.OpensabreCloud.OPENSABRE_CLOUD_REGION; +import static io.github.opensabre.boot.metadata.OpensabreVersion.OPENSABRE_FORMATTED_VERSION; +import static io.github.opensabre.boot.metadata.OpensabreVersion.OPENSABRE_VERSION; + /** * Opensabre环境变更初使化 * 将版本号初使化到环境变更中,方便应用后续扩展使用 */ @Slf4j public class OpensabreEnvConfig implements EnvironmentPostProcessor { - /** - * Opensabre版本号环境变更Key - */ - public static final String OPENSABRE_VERSION = "opensabre.version"; - /** - * Opensabre完整版本号环境变更Key - */ - public static final String OPENSABRE_FORMATTED_VERSION = "opensabre.formatted-version"; - /** - * Opensabre云部署AZ环境变量Key - */ - public static final String OPENSABRE_CLOUD_AZ = "opensabre.cloud.az"; - /** - * Opensabre云部署REGION环境变量Key - */ - public static final String OPENSABRE_CLOUD_REGION = "opensabre.cloud.region"; @Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { @@ -40,6 +32,7 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp MutablePropertySources propertySources = environment.getPropertySources(); propertySources.addFirst(getVersionEnv()); propertySources.addFirst(getCloudEnv()); + propertySources.addFirst(getGitProperties()); } /** @@ -65,5 +58,19 @@ private MapPropertySource getCloudEnv() { propertyMap.put(OPENSABRE_CLOUD_REGION, OpensabreCloud.getCloudRegion()); return new MapPropertySource("cloud", propertyMap); } -} + /** + * 加载git.properties构建元数据 + * + * @return PropertiesPropertySource + */ + private PropertiesPropertySource getGitProperties() { + Props props = new Props(); + try { + props = new Props("git.properties"); + } catch (NoResourceException exception) { + log.warn("load git properties: {}", exception.getMessage()); + } + return new PropertiesPropertySource("application", props.toProperties()); + } +} \ No newline at end of file diff --git a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/metadata/OpensabreCloud.java b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/metadata/OpensabreCloud.java index 5ace36b..99702e8 100644 --- a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/metadata/OpensabreCloud.java +++ b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/metadata/OpensabreCloud.java @@ -4,6 +4,14 @@ * 获取opensabre cloud相关信息,用于支持云原生多活等 */ public class OpensabreCloud { + /** + * Opensabre云部署AZ环境变量Key + */ + public static final String OPENSABRE_CLOUD_AZ = "opensabre.cloud.az"; + /** + * Opensabre云部署REGION环境变量Key + */ + public static final String OPENSABRE_CLOUD_REGION = "opensabre.cloud.region"; /** * 云部署时环境变量,代表可用区 */ diff --git a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/metadata/OpensabreVersion.java b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/metadata/OpensabreVersion.java index e81fc75..a992d50 100644 --- a/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/metadata/OpensabreVersion.java +++ b/opensabre-starter-boot/src/main/java/io/github/opensabre/boot/metadata/OpensabreVersion.java @@ -4,6 +4,14 @@ * 获取opensabre版本信息 */ public class OpensabreVersion { + /** + * Opensabre版本号环境变量Key + */ + public static final String OPENSABRE_VERSION = "opensabre.version"; + /** + * Opensabre完整版本号环境变量Key + */ + public static final String OPENSABRE_FORMATTED_VERSION = "opensabre.formatted-version"; /** * 私有构造方法,不允许初使化实例 */ diff --git a/opensabre-starter-boot/src/main/resources/banner.txt b/opensabre-starter-boot/src/main/resources/banner.txt index 84a3351..9ceb321 100644 --- a/opensabre-starter-boot/src/main/resources/banner.txt +++ b/opensabre-starter-boot/src/main/resources/banner.txt @@ -9,5 +9,5 @@ ${AnsiColor.CYAN}${AnsiStyle.BOLD} :: Java :: (v${java.version}) :: Spring Boot :: ${spring-boot.formatted-version} :: Opensabre :: ${opensabre.formatted-version} -:: Application :: ${application.formatted-version} +:: Application :: (v${git.build.version}) ${AnsiStyle.NORMAL} \ No newline at end of file diff --git a/opensabre-starter-register/src/main/java/io/github/opensabre/register/config/Metadata.java b/opensabre-starter-register/src/main/java/io/github/opensabre/register/config/Metadata.java index b91740f..0853232 100644 --- a/opensabre-starter-register/src/main/java/io/github/opensabre/register/config/Metadata.java +++ b/opensabre-starter-register/src/main/java/io/github/opensabre/register/config/Metadata.java @@ -6,7 +6,9 @@ import java.util.HashMap; import java.util.Map; -import static io.github.opensabre.boot.config.OpensabreEnvConfig.*; +import static io.github.opensabre.boot.metadata.OpensabreCloud.OPENSABRE_CLOUD_AZ; +import static io.github.opensabre.boot.metadata.OpensabreCloud.OPENSABRE_CLOUD_REGION; +import static io.github.opensabre.boot.metadata.OpensabreVersion.OPENSABRE_VERSION; /** * 应用元数据类 From b2676e2bbaf6b71370ad49556f75a3842c8045a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=B6=9B?= Date: Tue, 12 Mar 2024 23:17:11 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E5=BC=95=E5=85=A5git-commit=20plugin?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=BA=94=E7=94=A8=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=B3=A8=E5=86=8Cnacos=E5=85=83=E6=95=B0=E6=8D=AE=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- opensabre-base-dependencies/pom.xml | 78 +++++++++++++++++++ opensabre-starter-boot/pom.xml | 4 + .../main/resources/opensabre-boot.properties | 4 +- .../OpensabreNacosDiscoveryConfiguration.java | 28 +++---- .../src/main/resources/opensabre-register.yml | 4 +- .../DefaultGlobalExceptionHandlerAdvice.java | 6 +- 6 files changed, 98 insertions(+), 26 deletions(-) diff --git a/opensabre-base-dependencies/pom.xml b/opensabre-base-dependencies/pom.xml index 316dbe3..3831424 100644 --- a/opensabre-base-dependencies/pom.xml +++ b/opensabre-base-dependencies/pom.xml @@ -24,6 +24,7 @@ 2.7.5 1.4.13 3.11.0 + 4.9.10 3.2.3 2023.0.0 @@ -273,6 +274,83 @@ maven-surefire-plugin ${maven-surefire-plugin.version} + + pl.project13.maven + git-commit-id-plugin + ${git-commit-id-plugin.version} + + + get-the-git-infos + + revision + + + initialize + + + validate-the-git-infos + + validateRevision + + + package + + + + + ${project.basedir}/.git + + git + + yyyy-MM-dd'T'HH:mm:ssZ + + ${user.timezone} + + true + + true + ${project.build.outputDirectory}/git.properties + + true + + true + + true + + 7 + + flat + + + + false + + true + + 7 + + -dirty + + + + + + validating project version + + ${project.version} + + + + + + + diff --git a/opensabre-starter-boot/pom.xml b/opensabre-starter-boot/pom.xml index be34399..1230676 100644 --- a/opensabre-starter-boot/pom.xml +++ b/opensabre-starter-boot/pom.xml @@ -72,6 +72,10 @@ spring-boot-configuration-processor true + + cn.hutool + hutool-setting + org.springframework.boot diff --git a/opensabre-starter-boot/src/main/resources/opensabre-boot.properties b/opensabre-starter-boot/src/main/resources/opensabre-boot.properties index 4aaa80c..c1af70a 100644 --- a/opensabre-starter-boot/src/main/resources/opensabre-boot.properties +++ b/opensabre-starter-boot/src/main/resources/opensabre-boot.properties @@ -1,5 +1,5 @@ #==============springboot相关配置===============# -spring.web.resources.add-mappings=false +spring.web.resources.add-mappings=true spring.mvc.format.date-time=yyyy-MM-dd HH:mm:ss spring.mvc.format.date=yyyy-MM-dd spring.servlet.multipart.max-request-size=2MB @@ -16,7 +16,7 @@ jasypt.encryptor.password=${JASYPT_ENCRYPTOR_PASSWORD:Pa55w0rd@opensabre} #启用配置里的info开头的变量 management.info.env.enabled=true info.name=${spring.application.name} -info.version=${application.formatted-version} +info.application.version=${git.build.version} info.java.version=${java.version} info.opensabre.version=${opensabre.version} info.opensabre.cloud.az=${opensabre.cloud.az} diff --git a/opensabre-starter-register/src/main/java/io/github/opensabre/register/config/OpensabreNacosDiscoveryConfiguration.java b/opensabre-starter-register/src/main/java/io/github/opensabre/register/config/OpensabreNacosDiscoveryConfiguration.java index 7d8051e..446ef0f 100644 --- a/opensabre-starter-register/src/main/java/io/github/opensabre/register/config/OpensabreNacosDiscoveryConfiguration.java +++ b/opensabre-starter-register/src/main/java/io/github/opensabre/register/config/OpensabreNacosDiscoveryConfiguration.java @@ -2,15 +2,10 @@ import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled; import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.cloud.nacos.NacosServiceManager; -import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientConfiguration; -import com.alibaba.cloud.nacos.discovery.NacosWatch; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; /** * 初使化元数据,将元数据注册到注册中心 @@ -18,23 +13,18 @@ @Slf4j @AutoConfiguration @ConditionalOnNacosDiscoveryEnabled -@AutoConfigureBefore({NacosDiscoveryClientConfiguration.class}) public class OpensabreNacosDiscoveryConfiguration { + + @Resource + private NacosDiscoveryProperties nacosDiscoveryProperties; + /** * 将Opensabre元数据注册到注册中心 - * - * @param nacosServiceManager nacos服务管理对象 - * @param nacosDiscoveryProperties nacos服务发现配置对象 - * @return NacosWatch */ - @Bean - @ConditionalOnMissingBean - @ConditionalOnProperty(value = "spring.cloud.nacos.discovery.watch.enabled", matchIfMissing = true) - public NacosWatch nacosWatch(NacosServiceManager nacosServiceManager, - NacosDiscoveryProperties nacosDiscoveryProperties) { + @PostConstruct + public void initNacos() { log.info("Opensabre Metadata Register NacosDiscoveryConfig"); - //原来的元数据全部不变 + // 原来的元数据全部不变 nacosDiscoveryProperties.getMetadata().putAll(new Metadata().getMetadata()); - return new NacosWatch(nacosServiceManager, nacosDiscoveryProperties); } } diff --git a/opensabre-starter-register/src/main/resources/opensabre-register.yml b/opensabre-starter-register/src/main/resources/opensabre-register.yml index be69f6e..b1017e6 100644 --- a/opensabre-starter-register/src/main/resources/opensabre-register.yml +++ b/opensabre-starter-register/src/main/resources/opensabre-register.yml @@ -2,8 +2,6 @@ spring: cloud: nacos: discovery: - server-addr: ${REGISTER_HOST:localhost}:${REGISTER_PORT:8848} - watch: - enabled: false enabled: true + server-addr: ${REGISTER_HOST:localhost}:${REGISTER_PORT:8848} cluster-name: CLUSTER-${CLOUD_AZ:LOCAL} # 取环境变量AZ做为部分集群名:CLUSTER-SH,无环境变量默认为CLUSTER-LOCAL代表本地开发实例 \ No newline at end of file diff --git a/opensabre-web/src/main/java/io/github/opensabre/common/web/exception/DefaultGlobalExceptionHandlerAdvice.java b/opensabre-web/src/main/java/io/github/opensabre/common/web/exception/DefaultGlobalExceptionHandlerAdvice.java index a70f2e5..784cc76 100644 --- a/opensabre-web/src/main/java/io/github/opensabre/common/web/exception/DefaultGlobalExceptionHandlerAdvice.java +++ b/opensabre-web/src/main/java/io/github/opensabre/common/web/exception/DefaultGlobalExceptionHandlerAdvice.java @@ -3,6 +3,7 @@ import io.github.opensabre.common.core.entity.vo.Result; import io.github.opensabre.common.core.exception.BaseException; import io.github.opensabre.common.core.exception.SystemErrorType; +import jakarta.servlet.ServletException; import lombok.extern.slf4j.Slf4j; import org.springframework.core.annotation.Order; import org.springframework.http.HttpStatus; @@ -17,6 +18,7 @@ import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import org.springframework.web.multipart.MultipartException; import org.springframework.web.servlet.NoHandlerFoundException; +import org.springframework.web.servlet.resource.NoResourceFoundException; /** * 默认全局异常处理类 @@ -57,9 +59,9 @@ public Result notSupportedMethodException(HttpRequestMethodNotSupportedException return Result.fail(SystemErrorType.METHOD_NOT_SUPPORTED); } - @ExceptionHandler(value = {NoHandlerFoundException.class}) + @ExceptionHandler(value = {NoHandlerFoundException.class, NoResourceFoundException.class}) @ResponseStatus(HttpStatus.NOT_FOUND) - public Result noHandlerFoundException(NoHandlerFoundException ex) { + public Result noHandlerFoundException(ServletException ex) { log.warn("No static resource exception:{}", ex.getMessage()); return Result.fail(SystemErrorType.RESOURCE_NOT_FOUND, ex.getMessage()); } From e703c65d8f9a9bdca414ccdcd591a1cecab599ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=B6=9B?= Date: Wed, 13 Mar 2024 21:21:25 +0800 Subject: [PATCH 09/11] =?UTF-8?q?CI=E5=8D=87=E7=BA=A7JDK17?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/maven.yml | 4 ++-- .github/workflows/release.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 18a8cc6..447c52d 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -11,10 +11,10 @@ jobs: # 1. 声明 checkout 仓库代码到工作区 - uses: actions/checkout@v2 # 2. 安装Java 环境 这里会用到的参数就是 Git Action secrets中配置的, - - name: Set up JDK 1.11 + - name: Set up JDK 17 uses: actions/setup-java@v1 with: - java-version: 1.11 + java-version: 17 # 3.编译打包 - name: Build with Maven run: mvn -B package javadoc:javadoc --file pom.xml \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cad24de..46fb418 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Maven Central Repo uses: actions/setup-java@v1 with: - java-version: 1.11 + java-version: 17 server-id: sonatype-nexus-staging server-username: ${{ secrets.OSSRH_USER }} server-password: ${{ secrets.OSSRH_PASSWORD }} From 623a03291bb394c0825862923a154a6665b68bc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=B6=9B?= Date: Thu, 30 May 2024 15:57:56 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E5=BC=95=E5=85=A5git-commit=20plugin?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=BA=94=E7=94=A8=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=B3=A8=E5=86=8Cnacos=E5=85=83=E6=95=B0=E6=8D=AE=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- opensabre-base-dependencies/pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/opensabre-base-dependencies/pom.xml b/opensabre-base-dependencies/pom.xml index 3831424..d632312 100644 --- a/opensabre-base-dependencies/pom.xml +++ b/opensabre-base-dependencies/pom.xml @@ -357,11 +357,6 @@ org.apache.maven.plugins maven-compiler-plugin - - --enable-preview - 16 - 16 - From cf1154090f2fc6b08f3478eb4d31db37c10890f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=B6=9B?= Date: Thu, 30 May 2024 16:07:49 +0800 Subject: [PATCH 11/11] =?UTF-8?q?lombok=E5=8D=87=E7=BA=A7=E5=88=B01.18.30?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- opensabre-base-dependencies/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensabre-base-dependencies/pom.xml b/opensabre-base-dependencies/pom.xml index d632312..112002b 100644 --- a/opensabre-base-dependencies/pom.xml +++ b/opensabre-base-dependencies/pom.xml @@ -20,7 +20,7 @@ 17 17 - 1.18.24 + 1.18.30 2.7.5 1.4.13 3.11.0