From 17d8fce5f78f68e6e0d6393383789282a120fa10 Mon Sep 17 00:00:00 2001 From: smallchill Date: Wed, 6 Jan 2021 15:56:41 +0800 Subject: [PATCH 01/20] =?UTF-8?q?:tada:=203.0.0.RELEASE=20=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E5=8D=87=E7=BA=A7=E9=80=82=E9=85=8D=20SpringCloud=202?= =?UTF-8?q?020?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +- blade-core-boot/pom.xml | 2 +- .../config/BladeBootAutoConfiguration.java | 2 +- .../boot/config/BladeWebMvcConfiguration.java | 2 +- .../boot/config/MybatisPlusConfiguration.java | 2 +- .../core/boot/config/RetryConfiguration.java | 2 +- .../core/boot/logger/RequestLogAspect.java | 2 +- .../core/boot/tenant/TenantConfiguration.java | 2 +- .../src/main/resources/bootstrap.yml | 2 +- blade-core-cloud/pom.xml | 36 +-- .../cloud/client/BladeCloudApplication.java | 42 ++++ .../config/BladeCloudAutoConfiguration.java | 54 ++++ .../cloud/feign/BladeFallbackFactory.java | 2 +- .../feign/BladeFeignAutoConfiguration.java | 96 -------- .../core/cloud/feign/BladeFeignFallback.java | 4 +- .../core/cloud/feign/BladeFeignSentinel.java | 136 +++++++++++ .../core/cloud/feign/EnableBladeFeign.java | 3 + .../BladeAccountGetter.java | 4 +- .../BladeFeignAccountGetter.java} | 4 +- .../BladeFeignRequestHeaderInterceptor.java | 3 +- .../BladeHttpHeadersCallable.java | 8 +- .../BladeHttpHeadersContextHolder.java | 10 +- .../cloud/http/RestTemplateConfiguration.java | 14 +- .../http/RestTemplateHeaderInterceptor.java | 10 +- .../BladeHystrixAutoConfiguration.java | 71 ------ .../BladeHystrixConcurrencyStrategy.java | 93 ------- ....java => BladeFeignHeadersProperties.java} | 4 +- .../sentinel/BladeBlockExceptionHandler.java | 26 ++ .../BladeSentinelInvocationHandler.java | 168 +++++++++++++ .../BladeSpringMvcContract.java | 3 +- .../VersionMappingAutoConfiguration.java | 2 +- .../openfeign/BladeFeignClientsRegistrar.java | 230 ------------------ .../cloud/openfeign/BladeHystrixTargeter.java | 99 -------- .../cloud/openfeign/Targeter.java | 39 --- blade-core-develop/pom.xml | 2 +- blade-core-launch/pom.xml | 2 +- .../core/launch/StartEventListener.java | 2 +- .../config/BladeLaunchConfiguration.java | 2 +- .../core/launch/constant/AppConstant.java | 2 +- .../core/launch/server/ServerInfo.java | 2 +- blade-core-log/pom.xml | 2 +- .../BladeErrorMvcAutoConfiguration.java | 2 +- .../config/BladeLogToolAutoConfiguration.java | 2 +- .../core/log/error/BladeErrorController.java | 6 +- .../error/BladeRestExceptionTranslator.java | 2 +- blade-core-mybatis/pom.xml | 2 +- blade-core-oss/pom.xml | 2 +- .../core/oss/config/AliossConfiguration.java | 2 +- .../core/oss/config/QiniuConfiguration.java | 2 +- blade-core-report/pom.xml | 2 +- .../report/config/ReportConfiguration.java | 2 +- blade-core-secure/pom.xml | 2 +- .../secure/config/RegistryConfiguration.java | 2 +- .../secure/config/SecureConfiguration.java | 2 +- blade-core-social/pom.xml | 2 +- .../social/config/SocialConfiguration.java | 2 +- blade-core-swagger/pom.xml | 2 +- .../swagger/SwaggerAutoConfiguration.java | 2 +- .../core/swagger/SwaggerProperties.java | 2 +- blade-core-test/pom.xml | 2 +- .../springblade/core/test/BladeBaseTest.java | 30 --- .../springblade/core/test/BladeBootTest.java | 2 + ...gRunner.java => BladeSpringExtension.java} | 19 +- blade-core-tool/pom.xml | 2 +- .../tool/config/JacksonConfiguration.java | 2 +- .../tool/config/MessageConfiguration.java | 2 +- .../config/RedisTemplateConfiguration.java | 2 +- .../core/tool/config/ToolConfiguration.java | 2 +- .../core/tool/config/XssConfiguration.java | 2 +- .../core/tool/utils/RedisUtil.java | 4 +- .../springblade/core/tool/utils/WebUtil.java | 2 +- blade-core-transaction/pom.xml | 8 +- .../SeataFeignBlockingLoadBalancerClient.java | 33 +++ .../SeataFeignClientAutoConfiguration.java | 85 +++++++ .../seata/feign/SeataFeignObjectWrapper.java | 74 ++++++ ...ryableFeignBlockingLoadBalancerClient.java | 49 ++++ .../annotation/SeataCloudApplication.java | 5 +- .../config/DataSourceConfiguration.java | 4 +- pom.xml | 21 +- 79 files changed, 799 insertions(+), 788 deletions(-) create mode 100644 blade-core-cloud/src/main/java/org/springblade/core/cloud/client/BladeCloudApplication.java create mode 100644 blade-core-cloud/src/main/java/org/springblade/core/cloud/config/BladeCloudAutoConfiguration.java delete mode 100644 blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignAutoConfiguration.java create mode 100644 blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignSentinel.java rename blade-core-cloud/src/main/java/org/springblade/core/cloud/{hystrix => header}/BladeAccountGetter.java (91%) rename blade-core-cloud/src/main/java/org/springblade/core/cloud/{hystrix/BladeHystrixAccountGetter.java => header/BladeFeignAccountGetter.java} (91%) rename blade-core-cloud/src/main/java/org/springblade/core/cloud/{feign => header}/BladeFeignRequestHeaderInterceptor.java (92%) rename blade-core-cloud/src/main/java/org/springblade/core/cloud/{hystrix => header}/BladeHttpHeadersCallable.java (86%) rename blade-core-cloud/src/main/java/org/springblade/core/cloud/{hystrix => header}/BladeHttpHeadersContextHolder.java (91%) delete mode 100644 blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHystrixAutoConfiguration.java delete mode 100644 blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHystrixConcurrencyStrategy.java rename blade-core-cloud/src/main/java/org/springblade/core/cloud/props/{BladeHystrixHeadersProperties.java => BladeFeignHeadersProperties.java} (94%) create mode 100644 blade-core-cloud/src/main/java/org/springblade/core/cloud/sentinel/BladeBlockExceptionHandler.java create mode 100644 blade-core-cloud/src/main/java/org/springblade/core/cloud/sentinel/BladeSentinelInvocationHandler.java rename blade-core-cloud/src/main/java/org/springblade/core/cloud/{feign => version}/BladeSpringMvcContract.java (97%) delete mode 100644 blade-core-cloud/src/main/java/org/springframework/cloud/openfeign/BladeFeignClientsRegistrar.java delete mode 100644 blade-core-cloud/src/main/java/org/springframework/cloud/openfeign/BladeHystrixTargeter.java delete mode 100644 blade-core-cloud/src/main/java/org/springframework/cloud/openfeign/Targeter.java delete mode 100644 blade-core-test/src/main/java/org/springblade/core/test/BladeBaseTest.java rename blade-core-test/src/main/java/org/springblade/core/test/{BladeSpringRunner.java => BladeSpringExtension.java} (84%) create mode 100644 blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBlockingLoadBalancerClient.java create mode 100644 blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java create mode 100644 blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java create mode 100644 blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataRetryableFeignBlockingLoadBalancerClient.java diff --git a/README.md b/README.md index 69ebff8..72c87c4 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

Build Status - Coverage Status - Downloads + Coverage Status + Downloads

## SpringBlade微服务开发平台 @@ -14,7 +14,7 @@ * 极简封装了多租户底层,用更少的代码换来拓展性更强的SaaS多租户系统。 * 借鉴OAuth2,实现了多终端认证系统,可控制子系统的token权限互相隔离。 * 借鉴Security,封装了Secure模块,采用JWT做Token认证,可拓展集成Redis等细颗粒度控制方案。 -* 稳定生产了一年,经历了从Camden -> Greenwich的技术架构,也经历了从fat jar -> docker -> k8s + jenkins的部署架构 +* 稳定生产了一年,经历了从 Camden -> Hoxton -> 2020 的技术架构,也经历了从fat jar -> docker -> k8s + jenkins的部署架构 * 项目分包明确,规范微服务的开发模式,使包与包之间的分工清晰。 ## 架构图 diff --git a/blade-core-boot/pom.xml b/blade-core-boot/pom.xml index 2f8dd02..e972551 100644 --- a/blade-core-boot/pom.xml +++ b/blade-core-boot/pom.xml @@ -5,7 +5,7 @@ org.springblade blade-tool - 2.8.0 + 3.0.0 4.0.0 diff --git a/blade-core-boot/src/main/java/org/springblade/core/boot/config/BladeBootAutoConfiguration.java b/blade-core-boot/src/main/java/org/springblade/core/boot/config/BladeBootAutoConfiguration.java index 7cd56b3..25308a9 100644 --- a/blade-core-boot/src/main/java/org/springblade/core/boot/config/BladeBootAutoConfiguration.java +++ b/blade-core-boot/src/main/java/org/springblade/core/boot/config/BladeBootAutoConfiguration.java @@ -30,7 +30,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy; * @author Chill */ @Slf4j -@Configuration +@Configuration(proxyBeanMethods = false) @EnableConfigurationProperties({ BladeProperties.class }) diff --git a/blade-core-boot/src/main/java/org/springblade/core/boot/config/BladeWebMvcConfiguration.java b/blade-core-boot/src/main/java/org/springblade/core/boot/config/BladeWebMvcConfiguration.java index 969597b..a875ada 100644 --- a/blade-core-boot/src/main/java/org/springblade/core/boot/config/BladeWebMvcConfiguration.java +++ b/blade-core-boot/src/main/java/org/springblade/core/boot/config/BladeWebMvcConfiguration.java @@ -31,7 +31,7 @@ import java.util.List; * @author Chill */ @Slf4j -@Configuration +@Configuration(proxyBeanMethods = false) @EnableCaching @Order(Ordered.HIGHEST_PRECEDENCE) public class BladeWebMvcConfiguration implements WebMvcConfigurer { diff --git a/blade-core-boot/src/main/java/org/springblade/core/boot/config/MybatisPlusConfiguration.java b/blade-core-boot/src/main/java/org/springblade/core/boot/config/MybatisPlusConfiguration.java index abcf4d6..ac34e87 100644 --- a/blade-core-boot/src/main/java/org/springblade/core/boot/config/MybatisPlusConfiguration.java +++ b/blade-core-boot/src/main/java/org/springblade/core/boot/config/MybatisPlusConfiguration.java @@ -33,7 +33,7 @@ import org.springframework.context.annotation.Configuration; * * @author Chill */ -@Configuration +@Configuration(proxyBeanMethods = false) @AllArgsConstructor @MapperScan("org.springblade.**.mapper.**") public class MybatisPlusConfiguration { diff --git a/blade-core-boot/src/main/java/org/springblade/core/boot/config/RetryConfiguration.java b/blade-core-boot/src/main/java/org/springblade/core/boot/config/RetryConfiguration.java index 8530cf6..659d3fb 100644 --- a/blade-core-boot/src/main/java/org/springblade/core/boot/config/RetryConfiguration.java +++ b/blade-core-boot/src/main/java/org/springblade/core/boot/config/RetryConfiguration.java @@ -28,7 +28,7 @@ import org.springframework.retry.interceptor.RetryOperationsInterceptor; * @author Chill */ @Slf4j -@Configuration +@Configuration(proxyBeanMethods = false) public class RetryConfiguration { @Bean diff --git a/blade-core-boot/src/main/java/org/springblade/core/boot/logger/RequestLogAspect.java b/blade-core-boot/src/main/java/org/springblade/core/boot/logger/RequestLogAspect.java index c36e446..6e9008d 100644 --- a/blade-core-boot/src/main/java/org/springblade/core/boot/logger/RequestLogAspect.java +++ b/blade-core-boot/src/main/java/org/springblade/core/boot/logger/RequestLogAspect.java @@ -36,7 +36,7 @@ import java.util.concurrent.atomic.AtomicBoolean; */ @Slf4j @Aspect -@Configuration +@Configuration(proxyBeanMethods = false) @Profile({AppConstant.DEV_CODE, AppConstant.TEST_CODE}) public class RequestLogAspect { diff --git a/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/TenantConfiguration.java b/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/TenantConfiguration.java index 6cd8170..7693888 100644 --- a/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/TenantConfiguration.java +++ b/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/TenantConfiguration.java @@ -29,7 +29,7 @@ import org.springframework.context.annotation.Configuration; * * @author Chill */ -@Configuration +@Configuration(proxyBeanMethods = false) @AllArgsConstructor @AutoConfigureBefore(MybatisPlusConfiguration.class) @EnableConfigurationProperties(BladeTenantProperties.class) diff --git a/blade-core-boot/src/main/resources/bootstrap.yml b/blade-core-boot/src/main/resources/bootstrap.yml index 2b3841f..238a42d 100644 --- a/blade-core-boot/src/main/resources/bootstrap.yml +++ b/blade-core-boot/src/main/resources/bootstrap.yml @@ -97,7 +97,7 @@ mybatis-plus: swagger: title: SpringBlade 接口文档系统 description: SpringBlade 接口文档系统 - version: 2.8.0 + version: 3.0.0 license: Powered By SpringBlade licenseUrl: https://bladex.vip terms-of-service-url: https://bladex.vip diff --git a/blade-core-cloud/pom.xml b/blade-core-cloud/pom.xml index 9572333..fbbfaa0 100644 --- a/blade-core-cloud/pom.xml +++ b/blade-core-cloud/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 2.8.0 + 3.0.0 4.0.0 @@ -22,42 +22,22 @@ blade-core-secure ${blade.tool.version} - - - org.springframework.retry - spring-retry - - - io.github.openfeign - feign-okhttp - 10.4.0 - org.springframework.cloud spring-cloud-starter-openfeign - - - commons-logging - commons-logging - - - + + io.github.openfeign + feign-okhttp + org.springframework.cloud - spring-cloud-starter-netflix-hystrix - - - commons-logging - commons-logging - - + spring-cloud-starter-loadbalancer - - org.springframework.boot - spring-boot-starter-actuator + org.springframework.cloud + spring-cloud-starter-bootstrap diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/client/BladeCloudApplication.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/client/BladeCloudApplication.java new file mode 100644 index 0000000..effe1d4 --- /dev/null +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/client/BladeCloudApplication.java @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springblade.core.cloud.client; + +import org.springblade.core.launch.constant.AppConstant; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration; +import org.springframework.cloud.openfeign.EnableFeignClients; + +import java.lang.annotation.*; + +/** + * Cloud启动注解配置 + * + * @author Chill + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@EnableDiscoveryClient +@EnableCircuitBreaker +@EnableFeignClients(AppConstant.BASE_PACKAGES) +@SpringBootApplication(exclude = RibbonAutoConfiguration.class) +public @interface BladeCloudApplication { + +} diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/config/BladeCloudAutoConfiguration.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/config/BladeCloudAutoConfiguration.java new file mode 100644 index 0000000..e622088 --- /dev/null +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/config/BladeCloudAutoConfiguration.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springblade.core.cloud.config; + +import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration; +import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler; +import feign.Feign; +import org.springblade.core.cloud.feign.BladeFeignSentinel; +import org.springblade.core.cloud.sentinel.BladeBlockExceptionHandler; +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; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; + + +/** + * blade cloud 增强配置 + * + * @author Chill + */ +@Configuration(proxyBeanMethods = false) +@AutoConfigureBefore(SentinelFeignAutoConfiguration.class) +public class BladeCloudAutoConfiguration { + + @Bean + @Scope("prototype") + @ConditionalOnMissingBean + @ConditionalOnProperty(name = "feign.sentinel.enabled") + public Feign.Builder feignSentinelBuilder() { + return BladeFeignSentinel.builder(); + } + + @Bean + @ConditionalOnMissingBean + public BlockExceptionHandler blockExceptionHandler() { + return new BladeBlockExceptionHandler(); + } + +} diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFallbackFactory.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFallbackFactory.java index b6a524d..683fd5f 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFallbackFactory.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFallbackFactory.java @@ -16,9 +16,9 @@ package org.springblade.core.cloud.feign; import feign.Target; -import feign.hystrix.FallbackFactory; import lombok.AllArgsConstructor; import org.springframework.cglib.proxy.Enhancer; +import org.springframework.cloud.openfeign.FallbackFactory; /** * 默认 Fallback,避免写过多fallback类 diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignAutoConfiguration.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignAutoConfiguration.java deleted file mode 100644 index 9f0315d..0000000 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignAutoConfiguration.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2013-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springblade.core.cloud.feign; - -import com.netflix.hystrix.HystrixCommand; -import feign.Contract; -import feign.Feign; -import feign.RequestInterceptor; -import feign.hystrix.HystrixFeign; -import org.springblade.core.tool.convert.EnumToStringConverter; -import org.springblade.core.tool.convert.StringToEnumConverter; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.cloud.openfeign.BladeFeignClientsRegistrar; -import org.springframework.cloud.openfeign.BladeHystrixTargeter; -import org.springframework.cloud.openfeign.EnableFeignClients; -import org.springframework.cloud.openfeign.Targeter; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.context.annotation.Scope; -import org.springframework.core.convert.ConversionService; -import org.springframework.core.convert.converter.ConverterRegistry; - -import java.util.ArrayList; - - -/** - * blade feign 增强配置 - * - * @author L.cm - */ -@Configuration -@ConditionalOnClass(Feign.class) -@Import(BladeFeignClientsRegistrar.class) -@AutoConfigureAfter(EnableFeignClients.class) -public class BladeFeignAutoConfiguration { - - @Bean - @ConditionalOnMissingBean(Targeter.class) - public Targeter bladeFeignTargeter() { - return new BladeHystrixTargeter(); - } - - @Configuration("hystrixFeignConfiguration") - @ConditionalOnClass({ HystrixCommand.class, HystrixFeign.class }) - protected static class HystrixFeignConfiguration { - @Bean - @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) - @ConditionalOnProperty("feign.hystrix.enabled") - public Feign.Builder feignHystrixBuilder( - RequestInterceptor requestInterceptor, Contract feignContract) { - return HystrixFeign.builder() - .contract(feignContract) - .decode404() - .requestInterceptor(requestInterceptor); - } - - @Bean - @ConditionalOnMissingBean - public RequestInterceptor requestInterceptor() { - return new BladeFeignRequestHeaderInterceptor(); - } - } - - /** - * blade enum 《-》 String 转换配置 - * @param conversionService ConversionService - * @return SpringMvcContract - */ - @Bean - public Contract feignContract(@Qualifier("mvcConversionService") ConversionService conversionService) { - ConverterRegistry converterRegistry = ((ConverterRegistry) conversionService); - converterRegistry.addConverter(new EnumToStringConverter()); - converterRegistry.addConverter(new StringToEnumConverter()); - return new BladeSpringMvcContract(new ArrayList<>(), conversionService); - } -} diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignFallback.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignFallback.java index 17c51c3..a31c9de 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignFallback.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignFallback.java @@ -41,7 +41,7 @@ public class BladeFeignFallback implements MethodInterceptor { private final Class targetType; private final String targetName; private final Throwable cause; - private final String code = "code"; + private final static String CODE = "code"; @Nullable @Override @@ -66,7 +66,7 @@ public class BladeFeignFallback implements MethodInterceptor { // 转换成 jsonNode 读取,因为直接转换,可能 对方放回的并 不是 R 的格式。 JsonNode resultNode = JsonUtil.readTree(content); // 判断是否 R 格式 返回体 - if (resultNode.has(code)) { + if (resultNode.has(CODE)) { return JsonUtil.getInstance().convertValue(resultNode, R.class); } return R.fail(resultNode.toString()); diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignSentinel.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignSentinel.java new file mode 100644 index 0000000..8427eab --- /dev/null +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignSentinel.java @@ -0,0 +1,136 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springblade.core.cloud.feign; + +import com.alibaba.cloud.sentinel.feign.SentinelContractHolder; +import feign.Contract; +import feign.Feign; +import feign.InvocationHandlerFactory; +import feign.Target; +import lombok.SneakyThrows; +import org.springblade.core.cloud.sentinel.BladeSentinelInvocationHandler; +import org.springframework.beans.BeansException; +import org.springframework.cloud.openfeign.FallbackFactory; +import org.springframework.cloud.openfeign.FeignContext; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.util.ReflectionUtils; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.util.Map; + +/** + * feign集成sentinel自动配置 + * 重写 {@link com.alibaba.cloud.sentinel.feign.SentinelFeign} 适配最新API + * + * @author Chill + */ +public class BladeFeignSentinel { + + public static Builder builder() { + return new Builder(); + } + + public static final class Builder extends Feign.Builder + implements ApplicationContextAware { + private Contract contract = new Contract.Default(); + private ApplicationContext applicationContext; + private FeignContext feignContext; + + @Override + public Feign.Builder invocationHandlerFactory( + InvocationHandlerFactory invocationHandlerFactory) { + throw new UnsupportedOperationException(); + } + + @Override + public Builder contract(Contract contract) { + this.contract = contract; + return this; + } + + @Override + public Feign build() { + super.invocationHandlerFactory(new InvocationHandlerFactory() { + @SneakyThrows + @Override + public InvocationHandler create(Target target, + Map dispatch) { + Object feignClientFactoryBean = Builder.this.applicationContext.getBean("&" + target.type().getName()); + + Class fallback = (Class) getFieldValue(feignClientFactoryBean, "fallback"); + Class fallbackFactory = (Class) getFieldValue(feignClientFactoryBean, "fallbackFactory"); + String name = (String) getFieldValue(feignClientFactoryBean, "name"); + + Object fallbackInstance; + FallbackFactory fallbackFactoryInstance; + // 判断fallback类型 + if (void.class != fallback) { + fallbackInstance = getFromContext(name, "fallback", fallback, target.type()); + return new BladeSentinelInvocationHandler(target, dispatch, new FallbackFactory.Default(fallbackInstance)); + } + if (void.class != fallbackFactory) { + fallbackFactoryInstance = (FallbackFactory) getFromContext(name, "fallbackFactory", fallbackFactory, FallbackFactory.class); + return new BladeSentinelInvocationHandler(target, dispatch, fallbackFactoryInstance); + } + // 默认fallbackFactory + BladeFallbackFactory bladeFallbackFactory = new BladeFallbackFactory(target); + return new BladeSentinelInvocationHandler(target, dispatch, bladeFallbackFactory); + } + + private Object getFromContext(String name, String type, Class fallbackType, Class targetType) { + Object fallbackInstance = feignContext.getInstance(name, fallbackType); + if (fallbackInstance == null) { + throw new IllegalStateException( + String.format("No %s instance of type %s found for feign client %s", + type, fallbackType, name) + ); + } + + if (!targetType.isAssignableFrom(fallbackType)) { + throw new IllegalStateException( + String.format("Incompatible %s instance. Fallback/fallbackFactory of type %s is not assignable to %s for feign client %s", + type, fallbackType, targetType, name) + ); + } + return fallbackInstance; + } + }); + super.contract(new SentinelContractHolder(contract)); + return super.build(); + } + + private Object getFieldValue(Object instance, String fieldName) { + Field field = ReflectionUtils.findField(instance.getClass(), fieldName); + field.setAccessible(true); + try { + return field.get(instance); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + feignContext = this.applicationContext.getBean(FeignContext.class); + } + } + +} diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/EnableBladeFeign.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/EnableBladeFeign.java index c29b5b4..30f9619 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/EnableBladeFeign.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/EnableBladeFeign.java @@ -18,6 +18,8 @@ package org.springblade.core.cloud.feign; import org.springblade.core.launch.constant.AppConstant; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration; import org.springframework.cloud.openfeign.EnableFeignClients; import java.lang.annotation.*; @@ -31,6 +33,7 @@ import java.lang.annotation.*; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @EnableFeignClients(AppConstant.BASE_PACKAGES) +@EnableAutoConfiguration(exclude = RibbonAutoConfiguration.class) public @interface EnableBladeFeign { /** * Alias for the {@link #basePackages()} attribute. Allows for more concise annotation diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeAccountGetter.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/header/BladeAccountGetter.java similarity index 91% rename from blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeAccountGetter.java rename to blade-core-cloud/src/main/java/org/springblade/core/cloud/header/BladeAccountGetter.java index 43c967c..115cee2 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeAccountGetter.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/header/BladeAccountGetter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springblade.core.cloud.hystrix; +package org.springblade.core.cloud.header; import org.springblade.core.secure.BladeUser; import org.springblade.core.secure.utils.SecureUtil; @@ -27,7 +27,7 @@ import javax.servlet.http.HttpServletRequest; * * @author Chill */ -public class BladeAccountGetter implements BladeHystrixAccountGetter { +public class BladeAccountGetter implements BladeFeignAccountGetter { @Override public String get(HttpServletRequest request) { diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHystrixAccountGetter.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/header/BladeFeignAccountGetter.java similarity index 91% rename from blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHystrixAccountGetter.java rename to blade-core-cloud/src/main/java/org/springblade/core/cloud/header/BladeFeignAccountGetter.java index 57952de..0f086a4 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHystrixAccountGetter.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/header/BladeFeignAccountGetter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springblade.core.cloud.hystrix; +package org.springblade.core.cloud.header; import org.springframework.lang.Nullable; @@ -25,7 +25,7 @@ import javax.servlet.http.HttpServletRequest; * * @author L.cm */ -public interface BladeHystrixAccountGetter { +public interface BladeFeignAccountGetter { /** * 账号信息获取器 diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignRequestHeaderInterceptor.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/header/BladeFeignRequestHeaderInterceptor.java similarity index 92% rename from blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignRequestHeaderInterceptor.java rename to blade-core-cloud/src/main/java/org/springblade/core/cloud/header/BladeFeignRequestHeaderInterceptor.java index 1960d0d..d5b2649 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignRequestHeaderInterceptor.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/header/BladeFeignRequestHeaderInterceptor.java @@ -13,11 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springblade.core.cloud.feign; +package org.springblade.core.cloud.header; import feign.RequestInterceptor; import feign.RequestTemplate; -import org.springblade.core.cloud.hystrix.BladeHttpHeadersContextHolder; import org.springframework.http.HttpHeaders; /** diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHttpHeadersCallable.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/header/BladeHttpHeadersCallable.java similarity index 86% rename from blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHttpHeadersCallable.java rename to blade-core-cloud/src/main/java/org/springblade/core/cloud/header/BladeHttpHeadersCallable.java index 2bd1d02..831f2c0 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHttpHeadersCallable.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/header/BladeHttpHeadersCallable.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springblade.core.cloud.hystrix; +package org.springblade.core.cloud.header; -import org.springblade.core.cloud.props.BladeHystrixHeadersProperties; +import org.springblade.core.cloud.props.BladeFeignHeadersProperties; import org.springframework.http.HttpHeaders; import org.springframework.lang.Nullable; @@ -33,8 +33,8 @@ public class BladeHttpHeadersCallable implements Callable { private HttpHeaders httpHeaders; public BladeHttpHeadersCallable(Callable delegate, - @Nullable BladeHystrixAccountGetter accountGetter, - BladeHystrixHeadersProperties properties) { + @Nullable BladeFeignAccountGetter accountGetter, + BladeFeignHeadersProperties properties) { this.delegate = delegate; this.httpHeaders = BladeHttpHeadersContextHolder.toHeaders(accountGetter, properties); } diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHttpHeadersContextHolder.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/header/BladeHttpHeadersContextHolder.java similarity index 91% rename from blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHttpHeadersContextHolder.java rename to blade-core-cloud/src/main/java/org/springblade/core/cloud/header/BladeHttpHeadersContextHolder.java index 0712098..d9e323c 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHttpHeadersContextHolder.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/header/BladeHttpHeadersContextHolder.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springblade.core.cloud.hystrix; +package org.springblade.core.cloud.header; -import org.springblade.core.cloud.props.BladeHystrixHeadersProperties; +import org.springblade.core.cloud.props.BladeFeignHeadersProperties; import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.WebUtil; import org.springframework.core.NamedThreadLocal; @@ -35,7 +35,7 @@ import java.util.List; * @author L.cm */ public class BladeHttpHeadersContextHolder { - private static final ThreadLocal HTTP_HEADERS_HOLDER = new NamedThreadLocal<>("Blade hystrix HttpHeaders"); + private static final ThreadLocal HTTP_HEADERS_HOLDER = new NamedThreadLocal<>("Blade Feign HttpHeaders"); /** * 请求和转发的ip @@ -59,8 +59,8 @@ public class BladeHttpHeadersContextHolder { @Nullable public static HttpHeaders toHeaders( - @Nullable BladeHystrixAccountGetter accountGetter, - BladeHystrixHeadersProperties properties) { + @Nullable BladeFeignAccountGetter accountGetter, + BladeFeignHeadersProperties properties) { HttpServletRequest request = WebUtil.getRequest(); if (request == null) { return null; diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/http/RestTemplateConfiguration.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/http/RestTemplateConfiguration.java index cc4f8e0..beaf20f 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/http/RestTemplateConfiguration.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/http/RestTemplateConfiguration.java @@ -18,12 +18,13 @@ package org.springblade.core.cloud.http; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.AllArgsConstructor; -import org.springblade.core.cloud.hystrix.BladeHystrixAccountGetter; -import org.springblade.core.cloud.props.BladeHystrixHeadersProperties; +import org.springblade.core.cloud.header.BladeFeignAccountGetter; +import org.springblade.core.cloud.props.BladeFeignHeadersProperties; import org.springblade.core.tool.utils.Charsets; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.commons.httpclient.OkHttpClientConnectionPoolFactory; import org.springframework.cloud.commons.httpclient.OkHttpClientFactory; @@ -47,9 +48,10 @@ import java.util.concurrent.TimeUnit; * * @author L.cm */ -@Configuration -@ConditionalOnClass(okhttp3.OkHttpClient.class) +@Configuration(proxyBeanMethods = false) @AllArgsConstructor +@ConditionalOnClass(okhttp3.OkHttpClient.class) +@EnableConfigurationProperties(BladeFeignHeadersProperties.class) public class RestTemplateConfiguration { private final ObjectMapper objectMapper; @@ -135,8 +137,8 @@ public class RestTemplateConfiguration { @Bean public RestTemplateHeaderInterceptor requestHeaderInterceptor( - @Autowired(required = false) @Nullable BladeHystrixAccountGetter accountGetter, - BladeHystrixHeadersProperties properties) { + @Autowired(required = false) @Nullable BladeFeignAccountGetter accountGetter, + BladeFeignHeadersProperties properties) { return new RestTemplateHeaderInterceptor(accountGetter,properties); } diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/http/RestTemplateHeaderInterceptor.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/http/RestTemplateHeaderInterceptor.java index 2950676..4934758 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/http/RestTemplateHeaderInterceptor.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/http/RestTemplateHeaderInterceptor.java @@ -16,9 +16,9 @@ package org.springblade.core.cloud.http; import lombok.AllArgsConstructor; -import org.springblade.core.cloud.hystrix.BladeHttpHeadersContextHolder; -import org.springblade.core.cloud.hystrix.BladeHystrixAccountGetter; -import org.springblade.core.cloud.props.BladeHystrixHeadersProperties; +import org.springblade.core.cloud.header.BladeHttpHeadersContextHolder; +import org.springblade.core.cloud.header.BladeFeignAccountGetter; +import org.springblade.core.cloud.props.BladeFeignHeadersProperties; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; import org.springframework.http.client.ClientHttpRequestExecution; @@ -36,8 +36,8 @@ import java.io.IOException; @AllArgsConstructor public class RestTemplateHeaderInterceptor implements ClientHttpRequestInterceptor { @Nullable - private final BladeHystrixAccountGetter accountGetter; - private final BladeHystrixHeadersProperties properties; + private final BladeFeignAccountGetter accountGetter; + private final BladeFeignHeadersProperties properties; @Override public ClientHttpResponse intercept( diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHystrixAutoConfiguration.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHystrixAutoConfiguration.java deleted file mode 100644 index 9462c8a..0000000 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHystrixAutoConfiguration.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright (c) 2018-2028, DreamLu 卢春梦 (qq596392912@gmail.com). - *

- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.gnu.org/licenses/lgpl.html - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springblade.core.cloud.hystrix; - -import com.netflix.hystrix.Hystrix; -import com.netflix.hystrix.strategy.HystrixPlugins; -import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy; -import com.netflix.hystrix.strategy.eventnotifier.HystrixEventNotifier; -import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook; -import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisher; -import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy; -import org.springblade.core.cloud.props.BladeHystrixHeadersProperties; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Configuration; -import org.springframework.lang.Nullable; - -import javax.annotation.PostConstruct; - -/** - * Hystrix 配置 - * - * @author L.cm - */ -@Configuration -@ConditionalOnClass(Hystrix.class) -@EnableConfigurationProperties(BladeHystrixHeadersProperties.class) -public class BladeHystrixAutoConfiguration { - @Nullable - @Autowired(required = false) - private HystrixConcurrencyStrategy existingConcurrencyStrategy; - @Nullable - @Autowired(required = false) - private BladeHystrixAccountGetter accountGetter; - @Autowired - private BladeHystrixHeadersProperties properties; - - @PostConstruct - public void init() { - // Keeps references of existing Hystrix plugins. - HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); - HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); - HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); - HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook(); - - HystrixPlugins.reset(); - - // Registers existing plugins excepts the Concurrent Strategy plugin. - HystrixConcurrencyStrategy strategy = new BladeHystrixConcurrencyStrategy(existingConcurrencyStrategy, accountGetter, properties); - HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy); - HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); - HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); - HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); - HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); - } - -} diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHystrixConcurrencyStrategy.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHystrixConcurrencyStrategy.java deleted file mode 100644 index 76c1fa5..0000000 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/hystrix/BladeHystrixConcurrencyStrategy.java +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Copyright (c) 2018-2028, DreamLu 卢春梦 (qq596392912@gmail.com). - *

- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.gnu.org/licenses/lgpl.html - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springblade.core.cloud.hystrix; - -import com.netflix.hystrix.HystrixThreadPoolKey; -import com.netflix.hystrix.HystrixThreadPoolProperties; -import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy; -import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariable; -import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariableLifecycle; -import com.netflix.hystrix.strategy.properties.HystrixProperty; -import lombok.AllArgsConstructor; -import org.springblade.core.cloud.props.BladeHystrixHeadersProperties; -import org.springframework.lang.Nullable; - -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Callable; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -/** - * Hystrix传递ThreaLocal中的一些变量 - * - *

- * https://github.com/Netflix/Hystrix/issues/92#issuecomment-260548068 - * https://github.com/spring-cloud/spring-cloud-sleuth/issues/39 - * https://github.com/spring-cloud/spring-cloud-netflix/tree/master/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/hystrix/security - * https://github.com/spring-projects/spring-security/blob/master/core/src/main/java/org/springframework/security/concurrent/DelegatingSecurityContextCallable.java - *

- * - * @author L.cm - */ -@AllArgsConstructor -public class BladeHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy { - @Nullable - private final HystrixConcurrencyStrategy existingConcurrencyStrategy; - @Nullable - private final BladeHystrixAccountGetter accountGetter; - private final BladeHystrixHeadersProperties properties; - - @Override - public BlockingQueue getBlockingQueue(int maxQueueSize) { - return existingConcurrencyStrategy != null - ? existingConcurrencyStrategy.getBlockingQueue(maxQueueSize) - : super.getBlockingQueue(maxQueueSize); - } - - @Override - public HystrixRequestVariable getRequestVariable( - HystrixRequestVariableLifecycle rv) { - return existingConcurrencyStrategy != null - ? existingConcurrencyStrategy.getRequestVariable(rv) - : super.getRequestVariable(rv); - } - - @Override - public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey, - HystrixProperty corePoolSize, - HystrixProperty maximumPoolSize, - HystrixProperty keepAliveTime, TimeUnit unit, - BlockingQueue workQueue) { - return existingConcurrencyStrategy != null - ? existingConcurrencyStrategy.getThreadPool(threadPoolKey, corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue) - : super.getThreadPool(threadPoolKey, corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); - } - - @Override - public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolProperties threadPoolProperties) { - return existingConcurrencyStrategy != null - ? existingConcurrencyStrategy.getThreadPool(threadPoolKey, threadPoolProperties) - : super.getThreadPool(threadPoolKey, threadPoolProperties); - } - - @Override - public Callable wrapCallable(Callable callable) { - Callable wrapCallable = new BladeHttpHeadersCallable<>(callable, accountGetter, properties); - return existingConcurrencyStrategy != null - ? existingConcurrencyStrategy.wrapCallable(wrapCallable) - : super.wrapCallable(wrapCallable); - } -} diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/props/BladeHystrixHeadersProperties.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/props/BladeFeignHeadersProperties.java similarity index 94% rename from blade-core-cloud/src/main/java/org/springblade/core/cloud/props/BladeHystrixHeadersProperties.java rename to blade-core-cloud/src/main/java/org/springblade/core/cloud/props/BladeFeignHeadersProperties.java index a9364fd..b9e351a 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/props/BladeHystrixHeadersProperties.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/props/BladeFeignHeadersProperties.java @@ -32,8 +32,8 @@ import java.util.List; @Getter @Setter @RefreshScope -@ConfigurationProperties("blade.hystrix.headers") -public class BladeHystrixHeadersProperties { +@ConfigurationProperties("blade.feign.headers") +public class BladeFeignHeadersProperties { /** * 用于 聚合层 向调用层传递用户信息 的请求头,默认:x-blade-account diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/sentinel/BladeBlockExceptionHandler.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/sentinel/BladeBlockExceptionHandler.java new file mode 100644 index 0000000..12ddec4 --- /dev/null +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/sentinel/BladeBlockExceptionHandler.java @@ -0,0 +1,26 @@ +package org.springblade.core.cloud.sentinel; + +import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler; +import com.alibaba.csp.sentinel.slots.block.BlockException; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.jackson.JsonUtil; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Sentinel统一限流策略 + * + * @author Chill + */ +public class BladeBlockExceptionHandler implements BlockExceptionHandler { + @Override + public void handle(HttpServletRequest request, HttpServletResponse response, BlockException e) throws Exception { + // Return 429 (Too Many Requests) by default. + response.setStatus(HttpStatus.TOO_MANY_REQUESTS.value()); + response.setContentType(MediaType.APPLICATION_JSON_VALUE); + response.getWriter().print(JsonUtil.toJson(R.fail(e.getMessage()))); + } +} diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/sentinel/BladeSentinelInvocationHandler.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/sentinel/BladeSentinelInvocationHandler.java new file mode 100644 index 0000000..b386843 --- /dev/null +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/sentinel/BladeSentinelInvocationHandler.java @@ -0,0 +1,168 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springblade.core.cloud.sentinel; + +import com.alibaba.cloud.sentinel.feign.SentinelContractHolder; +import com.alibaba.csp.sentinel.Entry; +import com.alibaba.csp.sentinel.EntryType; +import com.alibaba.csp.sentinel.SphU; +import com.alibaba.csp.sentinel.Tracer; +import com.alibaba.csp.sentinel.context.ContextUtil; +import com.alibaba.csp.sentinel.slots.block.BlockException; +import feign.Feign; +import feign.InvocationHandlerFactory; +import feign.MethodMetadata; +import feign.Target; +import org.springframework.cloud.openfeign.FallbackFactory; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.LinkedHashMap; +import java.util.Map; + +import static feign.Util.checkNotNull; + +/** + * 重写SentinelInvocationHandler适配最新API + * + * @author Chill + */ +public class BladeSentinelInvocationHandler implements InvocationHandler { + + private final Target target; + + private final Map dispatch; + + private FallbackFactory fallbackFactory; + + private Map fallbackMethodMap; + + public BladeSentinelInvocationHandler(Target target, Map dispatch, + FallbackFactory fallbackFactory) { + this.target = checkNotNull(target, "target"); + this.dispatch = checkNotNull(dispatch, "dispatch"); + this.fallbackFactory = fallbackFactory; + this.fallbackMethodMap = toFallbackMethod(dispatch); + } + + public BladeSentinelInvocationHandler(Target target, Map dispatch) { + this.target = checkNotNull(target, "target"); + this.dispatch = checkNotNull(dispatch, "dispatch"); + } + + @Override + public Object invoke(final Object proxy, final Method method, final Object[] args) + throws Throwable { + if ("equals".equals(method.getName())) { + try { + Object otherHandler = args.length > 0 && args[0] != null + ? Proxy.getInvocationHandler(args[0]) : null; + return equals(otherHandler); + } catch (IllegalArgumentException e) { + return false; + } + } else if ("hashCode".equals(method.getName())) { + return hashCode(); + } else if ("toString".equals(method.getName())) { + return toString(); + } + + Object result; + InvocationHandlerFactory.MethodHandler methodHandler = this.dispatch.get(method); + // only handle by HardCodedTarget + if (target instanceof Target.HardCodedTarget) { + Target.HardCodedTarget hardCodedTarget = (Target.HardCodedTarget) target; + MethodMetadata methodMetadata = SentinelContractHolder.METADATA_MAP + .get(hardCodedTarget.type().getName() + + Feign.configKey(hardCodedTarget.type(), method)); + // resource default is HttpMethod:protocol://url + if (methodMetadata == null) { + result = methodHandler.invoke(args); + } else { + String resourceName = methodMetadata.template().method().toUpperCase() + + ":" + hardCodedTarget.url() + methodMetadata.template().path(); + Entry entry = null; + try { + ContextUtil.enter(resourceName); + entry = SphU.entry(resourceName, EntryType.OUT, 1, args); + result = methodHandler.invoke(args); + } catch (Throwable ex) { + // fallback handle + if (!BlockException.isBlockException(ex)) { + Tracer.trace(ex); + } + if (fallbackFactory != null) { + try { + Object fallbackResult = fallbackMethodMap.get(method) + .invoke(fallbackFactory.create(ex), args); + return fallbackResult; + } catch (IllegalAccessException e) { + // shouldn't happen as method is public due to being an + // interface + throw new AssertionError(e); + } catch (InvocationTargetException e) { + throw new AssertionError(e.getCause()); + } + } else { + // throw exception if fallbackFactory is null + throw ex; + } + } finally { + if (entry != null) { + entry.exit(1, args); + } + ContextUtil.exit(); + } + } + } else { + // other target type using default strategy + result = methodHandler.invoke(args); + } + + return result; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof BladeSentinelInvocationHandler) { + BladeSentinelInvocationHandler other = (BladeSentinelInvocationHandler) obj; + return target.equals(other.target); + } + return false; + } + + @Override + public int hashCode() { + return target.hashCode(); + } + + @Override + public String toString() { + return target.toString(); + } + + static Map toFallbackMethod(Map dispatch) { + Map result = new LinkedHashMap<>(); + for (Method method : dispatch.keySet()) { + method.setAccessible(true); + result.put(method, method); + } + return result; + } + +} diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeSpringMvcContract.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/version/BladeSpringMvcContract.java similarity index 97% rename from blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeSpringMvcContract.java rename to blade-core-cloud/src/main/java/org/springblade/core/cloud/version/BladeSpringMvcContract.java index 10cf4b7..507629e 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeSpringMvcContract.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/version/BladeSpringMvcContract.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springblade.core.cloud.feign; +package org.springblade.core.cloud.version; import feign.MethodMetadata; import org.springblade.core.cloud.annotation.ApiVersion; import org.springblade.core.cloud.annotation.UrlVersion; -import org.springblade.core.cloud.version.BladeMediaType; import org.springblade.core.tool.utils.StringPool; import org.springblade.core.tool.utils.StringUtil; import org.springframework.cloud.openfeign.AnnotatedParameterProcessor; diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/version/VersionMappingAutoConfiguration.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/version/VersionMappingAutoConfiguration.java index 2276e23..087caa3 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/version/VersionMappingAutoConfiguration.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/version/VersionMappingAutoConfiguration.java @@ -27,7 +27,7 @@ import org.springframework.context.annotation.Configuration; * * @author L.cm */ -@Configuration +@Configuration(proxyBeanMethods = false) @ConditionalOnWebApplication public class VersionMappingAutoConfiguration { @Bean diff --git a/blade-core-cloud/src/main/java/org/springframework/cloud/openfeign/BladeFeignClientsRegistrar.java b/blade-core-cloud/src/main/java/org/springframework/cloud/openfeign/BladeFeignClientsRegistrar.java deleted file mode 100644 index b6c635c..0000000 --- a/blade-core-cloud/src/main/java/org/springframework/cloud/openfeign/BladeFeignClientsRegistrar.java +++ /dev/null @@ -1,230 +0,0 @@ -/** - * Copyright (c) 2018-2028, DreamLu 卢春梦 (qq596392912@gmail.com). - *

- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.gnu.org/licenses/lgpl.html - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.cloud.openfeign; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.springblade.core.cloud.feign.BladeFeignAutoConfiguration; -import org.springframework.beans.factory.BeanClassLoaderAware; -import org.springframework.beans.factory.config.BeanDefinitionHolder; -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.context.EnvironmentAware; -import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; -import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.core.annotation.AnnotationAttributes; -import org.springframework.core.env.Environment; -import org.springframework.core.io.support.SpringFactoriesLoader; -import org.springframework.core.type.AnnotationMetadata; -import org.springframework.lang.Nullable; -import org.springframework.util.StringUtils; - -import java.util.List; -import java.util.Map; - -/** - * feign 自动配置 - * - * @author L.cm - */ -@NoArgsConstructor -public class BladeFeignClientsRegistrar implements ImportBeanDefinitionRegistrar, BeanClassLoaderAware, EnvironmentAware { - @Getter - private ClassLoader beanClassLoader; - @Getter - private Environment environment; - - @Override - public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) { - registerFeignClients(metadata, registry); - } - - @Override - public void setBeanClassLoader(ClassLoader classLoader) { - this.beanClassLoader = classLoader; - } - - private void registerFeignClients(AnnotationMetadata metadata, BeanDefinitionRegistry registry) { - List feignClients = SpringFactoriesLoader.loadFactoryNames(getSpringFactoriesLoaderFactoryClass(), getBeanClassLoader()); - // 如果 spring.factories 里为空 - if (feignClients.isEmpty()) { - return; - } - for (String className : feignClients) { - try { - Class clazz = beanClassLoader.loadClass(className); - AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz, FeignClient.class); - if (attributes == null) { - continue; - } - // 如果已经存在该 bean,支持原生的 Feign - if (registry.containsBeanDefinition(className)) { - continue; - } - registerClientConfiguration(registry, getClientName(attributes), attributes.get("configuration")); - - validate(attributes); - BeanDefinitionBuilder definition = BeanDefinitionBuilder.genericBeanDefinition(FeignClientFactoryBean.class); - definition.addPropertyValue("url", getUrl(attributes)); - definition.addPropertyValue("path", getPath(attributes)); - String name = getName(attributes); - definition.addPropertyValue("name", name); - - // 兼容最新版本的 spring-cloud-openfeign,尚未发布 - StringBuilder aliasBuilder = new StringBuilder(18); - if (attributes.containsKey("contextId")) { - String contextId = getContextId(attributes); - aliasBuilder.append(contextId); - definition.addPropertyValue("contextId", contextId); - } else { - aliasBuilder.append(name); - } - - definition.addPropertyValue("type", className); - definition.addPropertyValue("decode404", attributes.get("decode404")); - definition.addPropertyValue("fallback", attributes.get("fallback")); - definition.addPropertyValue("fallbackFactory", attributes.get("fallbackFactory")); - definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); - - AbstractBeanDefinition beanDefinition = definition.getBeanDefinition(); - - // alias - String alias = aliasBuilder.append("FeignClient").toString(); - - // has a default, won't be null - boolean primary = (Boolean)attributes.get("primary"); - - beanDefinition.setPrimary(primary); - - String qualifier = getQualifier(attributes); - if (StringUtils.hasText(qualifier)) { - alias = qualifier; - } - - BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className, new String[] { alias }); - BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry); - - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - } - } - - /** - * Return the class used by {@link SpringFactoriesLoader} to load configuration - * candidates. - * @return the factory class - */ - private Class getSpringFactoriesLoaderFactoryClass() { - return BladeFeignAutoConfiguration.class; - } - - private void validate(Map attributes) { - AnnotationAttributes annotation = AnnotationAttributes.fromMap(attributes); - // This blows up if an aliased property is overspecified - // FIXME annotation.getAliasedString("name", FeignClient.class, null); - FeignClientsRegistrar.validateFallback(annotation.getClass("fallback")); - FeignClientsRegistrar.validateFallbackFactory(annotation.getClass("fallbackFactory")); - } - - private String getName(Map attributes) { - String name = (String) attributes.get("serviceId"); - if (!StringUtils.hasText(name)) { - name = (String) attributes.get("name"); - } - if (!StringUtils.hasText(name)) { - name = (String) attributes.get("value"); - } - name = resolve(name); - return FeignClientsRegistrar.getName(name); - } - - private String getContextId(Map attributes) { - String contextId = (String) attributes.get("contextId"); - if (!StringUtils.hasText(contextId)) { - return getName(attributes); - } - - contextId = resolve(contextId); - return FeignClientsRegistrar.getName(contextId); - } - - private String resolve(String value) { - if (StringUtils.hasText(value)) { - return this.environment.resolvePlaceholders(value); - } - return value; - } - - private String getUrl(Map attributes) { - String url = resolve((String) attributes.get("url")); - return FeignClientsRegistrar.getUrl(url); - } - - private String getPath(Map attributes) { - String path = resolve((String) attributes.get("path")); - return FeignClientsRegistrar.getPath(path); - } - - @Nullable - private String getQualifier(@Nullable Map client) { - if (client == null) { - return null; - } - String qualifier = (String) client.get("qualifier"); - if (StringUtils.hasText(qualifier)) { - return qualifier; - } - return null; - } - - @Nullable - private String getClientName(@Nullable Map client) { - if (client == null) { - return null; - } - String value = (String) client.get("contextId"); - if (!StringUtils.hasText(value)) { - value = (String) client.get("value"); - } - if (!StringUtils.hasText(value)) { - value = (String) client.get("name"); - } - if (!StringUtils.hasText(value)) { - value = (String) client.get("serviceId"); - } - if (StringUtils.hasText(value)) { - return value; - } - - throw new IllegalStateException("Either 'name' or 'value' must be provided in @" + FeignClient.class.getSimpleName()); - } - - private void registerClientConfiguration(BeanDefinitionRegistry registry, Object name, Object configuration) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FeignClientSpecification.class); - builder.addConstructorArgValue(name); - builder.addConstructorArgValue(configuration); - registry.registerBeanDefinition(name + "." + FeignClientSpecification.class.getSimpleName(), builder.getBeanDefinition()); - } - - @Override - public void setEnvironment(Environment environment) { - this.environment = environment; - } - -} diff --git a/blade-core-cloud/src/main/java/org/springframework/cloud/openfeign/BladeHystrixTargeter.java b/blade-core-cloud/src/main/java/org/springframework/cloud/openfeign/BladeHystrixTargeter.java deleted file mode 100644 index f875cdd..0000000 --- a/blade-core-cloud/src/main/java/org/springframework/cloud/openfeign/BladeHystrixTargeter.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.springframework.cloud.openfeign; - -import feign.Feign; -import feign.Target; -import feign.hystrix.FallbackFactory; -import feign.hystrix.HystrixFeign; -import feign.hystrix.SetterFactory; -import org.springblade.core.cloud.feign.BladeFallbackFactory; -import org.springframework.lang.Nullable; - -/** - * 添加 blade 默认的 fallbackFactory L.cm 2019.01.19 - * - * @author L.cm - * @author Spencer Gibb - * @author Erik Kringen - */ -@SuppressWarnings("unchecked") -public class BladeHystrixTargeter implements Targeter { - - @Override - public T target(FeignClientFactoryBean factory, Feign.Builder feign, FeignContext context, - Target.HardCodedTarget target) { - if (!(feign instanceof HystrixFeign.Builder)) { - return feign.target(target); - } - HystrixFeign.Builder builder = (HystrixFeign.Builder) feign; - SetterFactory setterFactory = getOptional(factory.getName(), context, SetterFactory.class); - if (setterFactory != null) { - builder.setterFactory(setterFactory); - } - Class fallback = factory.getFallback(); - if (fallback != void.class) { - return targetWithFallback(factory.getName(), context, target, builder, fallback); - } - Class fallbackFactory = factory.getFallbackFactory(); - if (fallbackFactory != void.class) { - return targetWithFallbackFactory(factory.getName(), context, target, builder, fallbackFactory); - } - // blade 默认的 fallbackFactory - BladeFallbackFactory bladeFallbackFactory = new BladeFallbackFactory(target); - return (T) builder.target(target, bladeFallbackFactory); - } - - private T targetWithFallbackFactory(String feignClientName, FeignContext context, - Target.HardCodedTarget target, - HystrixFeign.Builder builder, - Class fallbackFactoryClass) { - FallbackFactory fallbackFactory = (FallbackFactory) - getFromContext("fallbackFactory", feignClientName, context, fallbackFactoryClass, FallbackFactory.class); - return builder.target(target, fallbackFactory); - } - - - private T targetWithFallback(String feignClientName, FeignContext context, - Target.HardCodedTarget target, - HystrixFeign.Builder builder, Class fallback) { - T fallbackInstance = getFromContext("fallback", feignClientName, context, fallback, target.type()); - return builder.target(target, fallbackInstance); - } - - private T getFromContext(String fallbackMechanism, String feignClientName, FeignContext context, Class beanType, - Class targetType) { - Object fallbackInstance = context.getInstance(feignClientName, beanType); - if (fallbackInstance == null) { - throw new IllegalStateException(String.format("No " + fallbackMechanism + - " instance of type %s found for feign client %s", beanType, feignClientName)); - } - - if (!targetType.isAssignableFrom(beanType)) { - throw new IllegalStateException(String.format( - "Incompatible " + fallbackMechanism + " instance. Fallback/fallbackFactory of " + - "type %s is not assignable to %s for feign client %s", beanType, targetType, feignClientName)); - } - return (T) fallbackInstance; - } - - @Nullable - private T getOptional(String feignClientName, FeignContext context, Class beanType) { - return context.getInstance(feignClientName, beanType); - } -} diff --git a/blade-core-cloud/src/main/java/org/springframework/cloud/openfeign/Targeter.java b/blade-core-cloud/src/main/java/org/springframework/cloud/openfeign/Targeter.java deleted file mode 100644 index bb49bd2..0000000 --- a/blade-core-cloud/src/main/java/org/springframework/cloud/openfeign/Targeter.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2013-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.springframework.cloud.openfeign; - -import feign.Feign; -import feign.Target; - -/** - * @author Spencer Gibb - */ -public interface Targeter { - /** - * target - * - * @param factory - * @param feign - * @param context - * @param target - * @param - * @return T - */ - T target(FeignClientFactoryBean factory, Feign.Builder feign, FeignContext context, - Target.HardCodedTarget target); -} diff --git a/blade-core-develop/pom.xml b/blade-core-develop/pom.xml index c9fcc45..ebbe868 100644 --- a/blade-core-develop/pom.xml +++ b/blade-core-develop/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 2.8.0 + 3.0.0 4.0.0 diff --git a/blade-core-launch/pom.xml b/blade-core-launch/pom.xml index 2109d38..991c6b3 100644 --- a/blade-core-launch/pom.xml +++ b/blade-core-launch/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 2.8.0 + 3.0.0 4.0.0 diff --git a/blade-core-launch/src/main/java/org/springblade/core/launch/StartEventListener.java b/blade-core-launch/src/main/java/org/springblade/core/launch/StartEventListener.java index f0b3f8a..34d31a8 100644 --- a/blade-core-launch/src/main/java/org/springblade/core/launch/StartEventListener.java +++ b/blade-core-launch/src/main/java/org/springblade/core/launch/StartEventListener.java @@ -30,7 +30,7 @@ import org.springframework.util.StringUtils; * @author Chill */ @Slf4j -@Configuration +@Configuration(proxyBeanMethods = false) public class StartEventListener { @Async diff --git a/blade-core-launch/src/main/java/org/springblade/core/launch/config/BladeLaunchConfiguration.java b/blade-core-launch/src/main/java/org/springblade/core/launch/config/BladeLaunchConfiguration.java index 38dd054..9bbb5c2 100644 --- a/blade-core-launch/src/main/java/org/springblade/core/launch/config/BladeLaunchConfiguration.java +++ b/blade-core-launch/src/main/java/org/springblade/core/launch/config/BladeLaunchConfiguration.java @@ -27,7 +27,7 @@ import org.springframework.core.annotation.Order; * * @author Chill */ -@Configuration +@Configuration(proxyBeanMethods = false) @AllArgsConstructor @Order(Ordered.HIGHEST_PRECEDENCE) @EnableConfigurationProperties({ diff --git a/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java b/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java index 3d00ded..bcf650a 100644 --- a/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java +++ b/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java @@ -25,7 +25,7 @@ public interface AppConstant { /** * 应用版本 */ - String APPLICATION_VERSION = "2.8.0"; + String APPLICATION_VERSION = "3.0.0"; /** * 基础包 diff --git a/blade-core-launch/src/main/java/org/springblade/core/launch/server/ServerInfo.java b/blade-core-launch/src/main/java/org/springblade/core/launch/server/ServerInfo.java index 3f989b6..176db96 100644 --- a/blade-core-launch/src/main/java/org/springblade/core/launch/server/ServerInfo.java +++ b/blade-core-launch/src/main/java/org/springblade/core/launch/server/ServerInfo.java @@ -28,7 +28,7 @@ import org.springframework.context.annotation.Configuration; * @author Chill */ @Getter -@Configuration +@Configuration(proxyBeanMethods = false) public class ServerInfo implements SmartInitializingSingleton { private final ServerProperties serverProperties; private String hostName; diff --git a/blade-core-log/pom.xml b/blade-core-log/pom.xml index 9c30b95..c7582d7 100644 --- a/blade-core-log/pom.xml +++ b/blade-core-log/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 2.8.0 + 3.0.0 4.0.0 diff --git a/blade-core-log/src/main/java/org/springblade/core/log/config/BladeErrorMvcAutoConfiguration.java b/blade-core-log/src/main/java/org/springblade/core/log/config/BladeErrorMvcAutoConfiguration.java index 2e2a72d..5221f11 100644 --- a/blade-core-log/src/main/java/org/springblade/core/log/config/BladeErrorMvcAutoConfiguration.java +++ b/blade-core-log/src/main/java/org/springblade/core/log/config/BladeErrorMvcAutoConfiguration.java @@ -41,7 +41,7 @@ import javax.servlet.Servlet; * * @author Chill */ -@Configuration +@Configuration(proxyBeanMethods = false) @AllArgsConstructor @ConditionalOnWebApplication @AutoConfigureBefore(ErrorMvcAutoConfiguration.class) diff --git a/blade-core-log/src/main/java/org/springblade/core/log/config/BladeLogToolAutoConfiguration.java b/blade-core-log/src/main/java/org/springblade/core/log/config/BladeLogToolAutoConfiguration.java index c0e9dd3..062a655 100644 --- a/blade-core-log/src/main/java/org/springblade/core/log/config/BladeLogToolAutoConfiguration.java +++ b/blade-core-log/src/main/java/org/springblade/core/log/config/BladeLogToolAutoConfiguration.java @@ -34,7 +34,7 @@ import org.springframework.context.annotation.Configuration; * * @author Chill */ -@Configuration +@Configuration(proxyBeanMethods = false) @AllArgsConstructor @ConditionalOnWebApplication public class BladeLogToolAutoConfiguration { diff --git a/blade-core-log/src/main/java/org/springblade/core/log/error/BladeErrorController.java b/blade-core-log/src/main/java/org/springblade/core/log/error/BladeErrorController.java index 6fd6e48..2daffea 100644 --- a/blade-core-log/src/main/java/org/springblade/core/log/error/BladeErrorController.java +++ b/blade-core-log/src/main/java/org/springblade/core/log/error/BladeErrorController.java @@ -18,6 +18,7 @@ package org.springblade.core.log.error; import org.springblade.core.tool.jackson.JsonUtil; import org.springframework.boot.autoconfigure.web.ErrorProperties; import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController; +import org.springframework.boot.web.error.ErrorAttributeOptions; import org.springframework.boot.web.servlet.error.ErrorAttributes; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -41,12 +42,13 @@ public class BladeErrorController extends BasicErrorController { @Override public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) { - Map body = getErrorAttributes(request, isIncludeStackTrace(request, MediaType.ALL)); + boolean includeStackTrace = isIncludeStackTrace(request, MediaType.ALL); + Map body = getErrorAttributes(request, (includeStackTrace) ? ErrorAttributeOptions.of(ErrorAttributeOptions.Include.STACK_TRACE) : ErrorAttributeOptions.defaults()); HttpStatus status = getStatus(request); response.setStatus(status.value()); MappingJackson2JsonView view = new MappingJackson2JsonView(); view.setObjectMapper(JsonUtil.getInstance()); - view.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); + view.setContentType(MediaType.APPLICATION_JSON_VALUE); return new ModelAndView(view, body); } diff --git a/blade-core-log/src/main/java/org/springblade/core/log/error/BladeRestExceptionTranslator.java b/blade-core-log/src/main/java/org/springblade/core/log/error/BladeRestExceptionTranslator.java index bc551be..cdee69e 100644 --- a/blade-core-log/src/main/java/org/springblade/core/log/error/BladeRestExceptionTranslator.java +++ b/blade-core-log/src/main/java/org/springblade/core/log/error/BladeRestExceptionTranslator.java @@ -55,7 +55,7 @@ import java.util.Set; * @author Chill */ @Slf4j -@Configuration +@Configuration(proxyBeanMethods = false) @ConditionalOnClass({Servlet.class, DispatcherServlet.class}) @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) @RestControllerAdvice diff --git a/blade-core-mybatis/pom.xml b/blade-core-mybatis/pom.xml index c314c6f..87301ca 100644 --- a/blade-core-mybatis/pom.xml +++ b/blade-core-mybatis/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 2.8.0 + 3.0.0 4.0.0 diff --git a/blade-core-oss/pom.xml b/blade-core-oss/pom.xml index 2e7b7a7..2da6e65 100644 --- a/blade-core-oss/pom.xml +++ b/blade-core-oss/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 2.8.0 + 3.0.0 4.0.0 diff --git a/blade-core-oss/src/main/java/org/springblade/core/oss/config/AliossConfiguration.java b/blade-core-oss/src/main/java/org/springblade/core/oss/config/AliossConfiguration.java index 29d3152..cc9f8d6 100644 --- a/blade-core-oss/src/main/java/org/springblade/core/oss/config/AliossConfiguration.java +++ b/blade-core-oss/src/main/java/org/springblade/core/oss/config/AliossConfiguration.java @@ -37,7 +37,7 @@ import org.springframework.context.annotation.Configuration; * * @author Chill */ -@Configuration +@Configuration(proxyBeanMethods = false) @AllArgsConstructor @AutoConfigureAfter(QiniuConfiguration.class) @EnableConfigurationProperties(OssProperties.class) diff --git a/blade-core-oss/src/main/java/org/springblade/core/oss/config/QiniuConfiguration.java b/blade-core-oss/src/main/java/org/springblade/core/oss/config/QiniuConfiguration.java index 52ab32a..ac37297 100644 --- a/blade-core-oss/src/main/java/org/springblade/core/oss/config/QiniuConfiguration.java +++ b/blade-core-oss/src/main/java/org/springblade/core/oss/config/QiniuConfiguration.java @@ -36,7 +36,7 @@ import org.springframework.context.annotation.Configuration; * * @author Chill */ -@Configuration +@Configuration(proxyBeanMethods = false) @AllArgsConstructor @EnableConfigurationProperties(OssProperties.class) @ConditionalOnProperty(value = "oss.name", havingValue = "qiniu") diff --git a/blade-core-report/pom.xml b/blade-core-report/pom.xml index 478351d..22bd9e6 100644 --- a/blade-core-report/pom.xml +++ b/blade-core-report/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 2.8.0 + 3.0.0 4.0.0 diff --git a/blade-core-report/src/main/java/org/springblade/core/report/config/ReportConfiguration.java b/blade-core-report/src/main/java/org/springblade/core/report/config/ReportConfiguration.java index ef28971..18f5d68 100644 --- a/blade-core-report/src/main/java/org/springblade/core/report/config/ReportConfiguration.java +++ b/blade-core-report/src/main/java/org/springblade/core/report/config/ReportConfiguration.java @@ -40,7 +40,7 @@ import javax.servlet.Servlet; * @author Chill */ @Order -@Configuration +@Configuration(proxyBeanMethods = false) @ConditionalOnProperty(value = "report.enabled", havingValue = "true", matchIfMissing = true) @EnableConfigurationProperties({ReportProperties.class, ReportDatabaseProperties.class}) @ImportResource("classpath:ureport-console-context.xml") diff --git a/blade-core-secure/pom.xml b/blade-core-secure/pom.xml index 0593b60..9f64081 100644 --- a/blade-core-secure/pom.xml +++ b/blade-core-secure/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 2.8.0 + 3.0.0 4.0.0 diff --git a/blade-core-secure/src/main/java/org/springblade/core/secure/config/RegistryConfiguration.java b/blade-core-secure/src/main/java/org/springblade/core/secure/config/RegistryConfiguration.java index 5c7fa37..d3b5a23 100644 --- a/blade-core-secure/src/main/java/org/springblade/core/secure/config/RegistryConfiguration.java +++ b/blade-core-secure/src/main/java/org/springblade/core/secure/config/RegistryConfiguration.java @@ -29,7 +29,7 @@ import org.springframework.core.annotation.Order; * @author Chill */ @Order -@Configuration +@Configuration(proxyBeanMethods = false) @AutoConfigureBefore(SecureConfiguration.class) public class RegistryConfiguration { diff --git a/blade-core-secure/src/main/java/org/springblade/core/secure/config/SecureConfiguration.java b/blade-core-secure/src/main/java/org/springblade/core/secure/config/SecureConfiguration.java index a77de31..5334ccf 100644 --- a/blade-core-secure/src/main/java/org/springblade/core/secure/config/SecureConfiguration.java +++ b/blade-core-secure/src/main/java/org/springblade/core/secure/config/SecureConfiguration.java @@ -39,7 +39,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; * @author Chill */ @Order -@Configuration +@Configuration(proxyBeanMethods = false) @AllArgsConstructor @EnableConfigurationProperties({BladeSecureProperties.class}) public class SecureConfiguration implements WebMvcConfigurer { diff --git a/blade-core-social/pom.xml b/blade-core-social/pom.xml index b1f44bc..b9cea42 100644 --- a/blade-core-social/pom.xml +++ b/blade-core-social/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 2.8.0 + 3.0.0 4.0.0 diff --git a/blade-core-social/src/main/java/org/springblade/core/social/config/SocialConfiguration.java b/blade-core-social/src/main/java/org/springblade/core/social/config/SocialConfiguration.java index 10bd116..b6d93b6 100644 --- a/blade-core-social/src/main/java/org/springblade/core/social/config/SocialConfiguration.java +++ b/blade-core-social/src/main/java/org/springblade/core/social/config/SocialConfiguration.java @@ -29,7 +29,7 @@ import org.springframework.context.annotation.Configuration; * * @author Chill */ -@Configuration +@Configuration(proxyBeanMethods = false) @EnableConfigurationProperties(SocialProperties.class) public class SocialConfiguration { diff --git a/blade-core-swagger/pom.xml b/blade-core-swagger/pom.xml index 5951fe1..f51669f 100644 --- a/blade-core-swagger/pom.xml +++ b/blade-core-swagger/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 2.8.0 + 3.0.0 4.0.0 diff --git a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerAutoConfiguration.java b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerAutoConfiguration.java index 34dcf05..3a22ef8 100644 --- a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerAutoConfiguration.java +++ b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerAutoConfiguration.java @@ -41,7 +41,7 @@ import java.util.List; * * @author Chill */ -@Configuration +@Configuration(proxyBeanMethods = false) @EnableSwagger @EnableConfigurationProperties(SwaggerProperties.class) @Import(BeanValidatorPluginsConfiguration.class) diff --git a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java index b53eeb1..d032e86 100644 --- a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java +++ b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java @@ -55,7 +55,7 @@ public class SwaggerProperties { /** * 版本 **/ - private String version = "2.8.0"; + private String version = "3.0.0"; /** * 许可证 **/ diff --git a/blade-core-test/pom.xml b/blade-core-test/pom.xml index 3c4b8ca..49a7863 100644 --- a/blade-core-test/pom.xml +++ b/blade-core-test/pom.xml @@ -5,7 +5,7 @@ org.springblade blade-tool - 2.8.0 + 3.0.0 4.0.0 diff --git a/blade-core-test/src/main/java/org/springblade/core/test/BladeBaseTest.java b/blade-core-test/src/main/java/org/springblade/core/test/BladeBaseTest.java deleted file mode 100644 index 67c830d..0000000 --- a/blade-core-test/src/main/java/org/springblade/core/test/BladeBaseTest.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) 2018-2028, DreamLu 卢春梦 (qq596392912@gmail.com). - *

- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.gnu.org/licenses/lgpl.html - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springblade.core.test; - -import org.junit.runner.RunWith; -import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; - -/** - * boot test 基类 - * - * @author L.cm - */ -@RunWith(BladeSpringRunner.class) -public abstract class BladeBaseTest extends AbstractJUnit4SpringContextTests { - -} diff --git a/blade-core-test/src/main/java/org/springblade/core/test/BladeBootTest.java b/blade-core-test/src/main/java/org/springblade/core/test/BladeBootTest.java index d6d4760..3c3f68b 100644 --- a/blade-core-test/src/main/java/org/springblade/core/test/BladeBootTest.java +++ b/blade-core-test/src/main/java/org/springblade/core/test/BladeBootTest.java @@ -16,6 +16,7 @@ package org.springblade.core.test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.core.annotation.AliasFor; @@ -31,6 +32,7 @@ import java.lang.annotation.*; @Documented @Inherited @SpringBootTest +@ExtendWith(BladeSpringExtension.class) public @interface BladeBootTest { /** * 服务名:appName diff --git a/blade-core-test/src/main/java/org/springblade/core/test/BladeSpringRunner.java b/blade-core-test/src/main/java/org/springblade/core/test/BladeSpringExtension.java similarity index 84% rename from blade-core-test/src/main/java/org/springblade/core/test/BladeSpringRunner.java rename to blade-core-test/src/main/java/org/springblade/core/test/BladeSpringExtension.java index bb456c0..8f11c31 100644 --- a/blade-core-test/src/main/java/org/springblade/core/test/BladeSpringRunner.java +++ b/blade-core-test/src/main/java/org/springblade/core/test/BladeSpringExtension.java @@ -17,7 +17,7 @@ package org.springblade.core.test; -import org.junit.runners.model.InitializationError; +import org.junit.jupiter.api.extension.ExtensionContext; import org.springblade.core.launch.BladeApplication; import org.springblade.core.launch.constant.AppConstant; import org.springblade.core.launch.constant.NacosConstant; @@ -25,7 +25,8 @@ import org.springblade.core.launch.constant.SentinelConstant; import org.springblade.core.launch.service.LauncherService; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.lang.NonNull; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.util.*; import java.util.stream.Collectors; @@ -35,14 +36,16 @@ import java.util.stream.Collectors; * * @author L.cm */ -public class BladeSpringRunner extends SpringJUnit4ClassRunner { +public class BladeSpringExtension extends SpringExtension { - public BladeSpringRunner(Class clazz) throws InitializationError { - super(clazz); - setUpTestClass(clazz); + @Override + public void beforeAll(@NonNull ExtensionContext context) throws Exception { + super.beforeAll(context); + setUpTestClass(context); } - private void setUpTestClass(Class clazz) { + private void setUpTestClass(ExtensionContext context) { + Class clazz = context.getRequiredTestClass(); BladeBootTest bladeBootTest = AnnotationUtils.getAnnotation(clazz, BladeBootTest.class); if (bladeBootTest == null) { throw new BladeBootTestException(String.format("%s must be @BladeBootTest .", clazz)); @@ -74,7 +77,7 @@ public class BladeSpringRunner extends SpringJUnit4ClassRunner { launcherList.stream().sorted(Comparator.comparing(LauncherService::getOrder)).collect(Collectors.toList()) .forEach(launcherService -> launcherService.launcher(builder, appName, profile)); } - System.err.println(String.format("---[junit.test]:[%s]---启动中,读取到的环境变量:[%s]", appName, profile)); + System.err.printf("---[junit.test]:[%s]---启动中,读取到的环境变量:[%s]%n", appName, profile); } } diff --git a/blade-core-tool/pom.xml b/blade-core-tool/pom.xml index 90f8d10..5d6fc4e 100644 --- a/blade-core-tool/pom.xml +++ b/blade-core-tool/pom.xml @@ -6,7 +6,7 @@ org.springblade blade-tool - 2.8.0 + 3.0.0 4.0.0 diff --git a/blade-core-tool/src/main/java/org/springblade/core/tool/config/JacksonConfiguration.java b/blade-core-tool/src/main/java/org/springblade/core/tool/config/JacksonConfiguration.java index f1216eb..a5b0058 100644 --- a/blade-core-tool/src/main/java/org/springblade/core/tool/config/JacksonConfiguration.java +++ b/blade-core-tool/src/main/java/org/springblade/core/tool/config/JacksonConfiguration.java @@ -41,7 +41,7 @@ import java.util.TimeZone; * * @author Chill */ -@Configuration +@Configuration(proxyBeanMethods = false) @AllArgsConstructor @ConditionalOnClass(ObjectMapper.class) @AutoConfigureBefore(JacksonAutoConfiguration.class) diff --git a/blade-core-tool/src/main/java/org/springblade/core/tool/config/MessageConfiguration.java b/blade-core-tool/src/main/java/org/springblade/core/tool/config/MessageConfiguration.java index c3f3344..51fb28c 100644 --- a/blade-core-tool/src/main/java/org/springblade/core/tool/config/MessageConfiguration.java +++ b/blade-core-tool/src/main/java/org/springblade/core/tool/config/MessageConfiguration.java @@ -34,7 +34,7 @@ import java.util.List; * * @author Chill */ -@Configuration +@Configuration(proxyBeanMethods = false) @AllArgsConstructor @Order(Ordered.HIGHEST_PRECEDENCE) public class MessageConfiguration implements WebMvcConfigurer { diff --git a/blade-core-tool/src/main/java/org/springblade/core/tool/config/RedisTemplateConfiguration.java b/blade-core-tool/src/main/java/org/springblade/core/tool/config/RedisTemplateConfiguration.java index 0647573..5f0ee66 100644 --- a/blade-core-tool/src/main/java/org/springblade/core/tool/config/RedisTemplateConfiguration.java +++ b/blade-core-tool/src/main/java/org/springblade/core/tool/config/RedisTemplateConfiguration.java @@ -41,7 +41,7 @@ import java.time.Duration; * @author Chill */ @EnableCaching -@Configuration +@Configuration(proxyBeanMethods = false) @AutoConfigureBefore(RedisAutoConfiguration.class) public class RedisTemplateConfiguration { diff --git a/blade-core-tool/src/main/java/org/springblade/core/tool/config/ToolConfiguration.java b/blade-core-tool/src/main/java/org/springblade/core/tool/config/ToolConfiguration.java index b0346dc..9dfc257 100644 --- a/blade-core-tool/src/main/java/org/springblade/core/tool/config/ToolConfiguration.java +++ b/blade-core-tool/src/main/java/org/springblade/core/tool/config/ToolConfiguration.java @@ -28,7 +28,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; * * @author Chill */ -@Configuration +@Configuration(proxyBeanMethods = false) @Order(Ordered.HIGHEST_PRECEDENCE) public class ToolConfiguration implements WebMvcConfigurer { diff --git a/blade-core-tool/src/main/java/org/springblade/core/tool/config/XssConfiguration.java b/blade-core-tool/src/main/java/org/springblade/core/tool/config/XssConfiguration.java index 84c6eca..cf3995a 100644 --- a/blade-core-tool/src/main/java/org/springblade/core/tool/config/XssConfiguration.java +++ b/blade-core-tool/src/main/java/org/springblade/core/tool/config/XssConfiguration.java @@ -33,7 +33,7 @@ import javax.servlet.DispatcherType; * * @author Chill */ -@Configuration +@Configuration(proxyBeanMethods = false) @AllArgsConstructor @ConditionalOnProperty(value = "blade.xss.enabled", havingValue = "true") @EnableConfigurationProperties({XssProperties.class, XssUrlProperties.class}) diff --git a/blade-core-tool/src/main/java/org/springblade/core/tool/utils/RedisUtil.java b/blade-core-tool/src/main/java/org/springblade/core/tool/utils/RedisUtil.java index 8f67226..ea095f2 100644 --- a/blade-core-tool/src/main/java/org/springblade/core/tool/utils/RedisUtil.java +++ b/blade-core-tool/src/main/java/org/springblade/core/tool/utils/RedisUtil.java @@ -3,6 +3,7 @@ package org.springblade.core.tool.utils; import lombok.AllArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Set; @@ -69,13 +70,12 @@ public class RedisUtil { * * @param key 可以传一个值 或多个 */ - @SuppressWarnings("unchecked") public void del(String... key) { if (key != null && key.length > 0) { if (key.length == 1) { redisTemplate.delete(key[0]); } else { - redisTemplate.delete(CollectionUtil.arrayToList(key)); + redisTemplate.delete(Arrays.asList(key)); } } } diff --git a/blade-core-tool/src/main/java/org/springblade/core/tool/utils/WebUtil.java b/blade-core-tool/src/main/java/org/springblade/core/tool/utils/WebUtil.java index bab680a..8259090 100644 --- a/blade-core-tool/src/main/java/org/springblade/core/tool/utils/WebUtil.java +++ b/blade-core-tool/src/main/java/org/springblade/core/tool/utils/WebUtil.java @@ -127,7 +127,7 @@ public class WebUtil extends org.springframework.web.util.WebUtils { * @param result 结果对象 */ public static void renderJson(HttpServletResponse response, Object result) { - renderJson(response, result, MediaType.APPLICATION_JSON_UTF8_VALUE); + renderJson(response, result, MediaType.APPLICATION_JSON_VALUE); } /** diff --git a/blade-core-transaction/pom.xml b/blade-core-transaction/pom.xml index 1ee758c..0828955 100644 --- a/blade-core-transaction/pom.xml +++ b/blade-core-transaction/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 2.8.0 + 3.0.0 4.0.0 @@ -15,11 +15,17 @@ jar + org.springblade blade-core-mybatis ${blade.tool.version} + + org.springblade + blade-core-cloud + ${blade.tool.version} + org.springframework.cloud diff --git a/blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBlockingLoadBalancerClient.java b/blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBlockingLoadBalancerClient.java new file mode 100644 index 0000000..2bf6c56 --- /dev/null +++ b/blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBlockingLoadBalancerClient.java @@ -0,0 +1,33 @@ +package com.alibaba.cloud.seata.feign; + +import feign.Client; +import feign.Request; +import feign.Response; +import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties; +import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient; +import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; +import org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalancerClient; + +import java.io.IOException; + +/** + * 重写SeataFeignBlockingLoadBalancerClient以适配最新API + * + * @author Chill + */ +public class SeataFeignBlockingLoadBalancerClient extends FeignBlockingLoadBalancerClient { + + public SeataFeignBlockingLoadBalancerClient(Client delegate, + BlockingLoadBalancerClient loadBalancerClient, + SeataFeignObjectWrapper seataFeignObjectWrapper, + LoadBalancerProperties properties, + LoadBalancerClientFactory loadBalancerClientFactory) { + super((Client) seataFeignObjectWrapper.wrap(delegate), loadBalancerClient, properties, loadBalancerClientFactory); + } + + @Override + public Response execute(Request request, Request.Options options) throws IOException { + return super.execute(request, options); + } + +} diff --git a/blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java b/blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java new file mode 100644 index 0000000..d0fc70f --- /dev/null +++ b/blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java @@ -0,0 +1,85 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.cloud.seata.feign; + +import feign.Client; +import feign.Feign; +import feign.Retryer; +import lombok.RequiredArgsConstructor; +import org.springblade.core.cloud.feign.BladeFeignSentinel; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory; +import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties; +import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; +import org.springframework.cloud.openfeign.FeignAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; + +/** + * 重写SeataFeignClientAutoConfiguration以适配最新API + * + * @author Chill + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnClass(Client.class) +@AutoConfigureBefore(FeignAutoConfiguration.class) +public class SeataFeignClientAutoConfiguration { + + @Bean + @Scope("prototype") + @ConditionalOnClass(name = "com.alibaba.csp.sentinel.SphU") + @ConditionalOnProperty(name = "feign.sentinel.enabled", havingValue = "true") + Feign.Builder feignSentinelBuilder(BeanFactory beanFactory) { + return BladeFeignSentinel.builder().retryer(Retryer.NEVER_RETRY) + .client(new SeataFeignClient(beanFactory)); + } + + @Bean + @ConditionalOnMissingBean + @Scope("prototype") + Feign.Builder feignBuilder(BeanFactory beanFactory) { + return SeataFeignBuilder.builder(beanFactory); + } + + @Configuration(proxyBeanMethods = false) + @RequiredArgsConstructor + protected static class FeignBeanPostProcessorConfiguration { + private final LoadBalancedRetryFactory loadBalancedRetryFactory; + private final LoadBalancerProperties properties; + private final LoadBalancerClientFactory loadBalancerClientFactory; + + @Bean + SeataBeanPostProcessor seataBeanPostProcessor(SeataFeignObjectWrapper seataFeignObjectWrapper) { + return new SeataBeanPostProcessor(seataFeignObjectWrapper); + } + + @Bean + SeataContextBeanPostProcessor seataContextBeanPostProcessor(BeanFactory beanFactory) { + return new SeataContextBeanPostProcessor(beanFactory); + } + + @Bean + SeataFeignObjectWrapper seataFeignObjectWrapper(BeanFactory beanFactory) { + return new SeataFeignObjectWrapper(beanFactory, loadBalancedRetryFactory, properties, loadBalancerClientFactory); + } + + } +} diff --git a/blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java b/blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java new file mode 100644 index 0000000..436300f --- /dev/null +++ b/blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java @@ -0,0 +1,74 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.cloud.seata.feign; + +import feign.Client; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory; +import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties; +import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient; +import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; +import org.springframework.cloud.netflix.ribbon.SpringClientFactory; +import org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalancerClient; +import org.springframework.cloud.openfeign.loadbalancer.RetryableFeignBlockingLoadBalancerClient; + +/** + * 重写SeataFeignObjectWrapper以适配最新API + * + * @author Chill + */ +public class SeataFeignObjectWrapper { + + private final BeanFactory beanFactory; + private final LoadBalancedRetryFactory loadBalancedRetryFactory; + private final LoadBalancerProperties properties; + private final LoadBalancerClientFactory loadBalancerClientFactory; + + private SpringClientFactory springClientFactory; + + SeataFeignObjectWrapper(BeanFactory beanFactory, LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerProperties properties, LoadBalancerClientFactory loadBalancerClientFactory) { + this.beanFactory = beanFactory; + this.loadBalancedRetryFactory = loadBalancedRetryFactory; + this.properties = properties; + this.loadBalancerClientFactory = loadBalancerClientFactory; + } + + Object wrap(Object bean) { + if (bean instanceof Client && !(bean instanceof SeataFeignClient)) { + if (bean instanceof FeignBlockingLoadBalancerClient) { + FeignBlockingLoadBalancerClient client = (FeignBlockingLoadBalancerClient) bean; + return new SeataFeignBlockingLoadBalancerClient(client.getDelegate(), + beanFactory.getBean(BlockingLoadBalancerClient.class), this, properties, loadBalancerClientFactory); + } + if (bean instanceof RetryableFeignBlockingLoadBalancerClient) { + RetryableFeignBlockingLoadBalancerClient client = (RetryableFeignBlockingLoadBalancerClient) bean; + return new SeataRetryableFeignBlockingLoadBalancerClient(client.getDelegate(), + beanFactory.getBean(BlockingLoadBalancerClient.class), this, loadBalancedRetryFactory, properties, loadBalancerClientFactory); + } + return new SeataFeignClient(this.beanFactory, (Client) bean); + } + return bean; + } + + SpringClientFactory clientFactory() { + if (this.springClientFactory == null) { + this.springClientFactory = this.beanFactory + .getBean(SpringClientFactory.class); + } + return this.springClientFactory; + } + +} diff --git a/blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataRetryableFeignBlockingLoadBalancerClient.java b/blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataRetryableFeignBlockingLoadBalancerClient.java new file mode 100644 index 0000000..31cc2dc --- /dev/null +++ b/blade-core-transaction/src/main/java/com/alibaba/cloud/seata/feign/SeataRetryableFeignBlockingLoadBalancerClient.java @@ -0,0 +1,49 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.cloud.seata.feign; + +import feign.Client; +import feign.Request; +import feign.Response; +import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory; +import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties; +import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient; +import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; +import org.springframework.cloud.openfeign.loadbalancer.RetryableFeignBlockingLoadBalancerClient; + +import java.io.IOException; + +/** + * 拓展SeataRetryableFeignBlockingLoadBalancerClient以适配最新API + * + * @author Chill + */ +public class SeataRetryableFeignBlockingLoadBalancerClient extends RetryableFeignBlockingLoadBalancerClient { + + public SeataRetryableFeignBlockingLoadBalancerClient(Client delegate, + BlockingLoadBalancerClient loadBalancerClient, + SeataFeignObjectWrapper seataFeignObjectWrapper, + LoadBalancedRetryFactory loadBalancedRetryFactory, + LoadBalancerProperties properties, + LoadBalancerClientFactory loadBalancerClientFactory) { + super((Client) seataFeignObjectWrapper.wrap(delegate), loadBalancerClient, loadBalancedRetryFactory, properties, loadBalancerClientFactory); + } + + @Override + public Response execute(Request request, Request.Options options) throws IOException { + return super.execute(request, options); + } +} diff --git a/blade-core-transaction/src/main/java/org/springblade/core/transaction/annotation/SeataCloudApplication.java b/blade-core-transaction/src/main/java/org/springblade/core/transaction/annotation/SeataCloudApplication.java index 2a9ed85..edc3566 100644 --- a/blade-core-transaction/src/main/java/org/springblade/core/transaction/annotation/SeataCloudApplication.java +++ b/blade-core-transaction/src/main/java/org/springblade/core/transaction/annotation/SeataCloudApplication.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2018-2028, lengleng (wangiegie@gmail.com). + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). *

* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration; import java.lang.annotation.*; @@ -33,7 +34,7 @@ import java.lang.annotation.*; @Inherited @EnableDiscoveryClient @EnableCircuitBreaker -@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, RibbonAutoConfiguration.class}) public @interface SeataCloudApplication { } diff --git a/blade-core-transaction/src/main/java/org/springblade/core/transaction/config/DataSourceConfiguration.java b/blade-core-transaction/src/main/java/org/springblade/core/transaction/config/DataSourceConfiguration.java index 2d6424e..a6cfb48 100644 --- a/blade-core-transaction/src/main/java/org/springblade/core/transaction/config/DataSourceConfiguration.java +++ b/blade-core-transaction/src/main/java/org/springblade/core/transaction/config/DataSourceConfiguration.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2018-2028, lengleng (wangiegie@gmail.com). + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). *

* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import org.springframework.context.annotation.Configuration; * * @author Chill */ -@Configuration +@Configuration(proxyBeanMethods = false) public class DataSourceConfiguration { } diff --git a/pom.xml b/pom.xml index a610c2d..8d90a88 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springblade blade-tool - 2.8.0 + 3.0.0 pom blade-tool @@ -36,24 +36,24 @@ - 2.8.0 + 3.0.0 1.8 3.8.0 2.10.5 1.6.2 - 2.0.6 - 3.4.0 + 2.0.8 + 3.4.1 1.6.0 3.4.2 - 2.3.0 + 2.3.1 1.2.5 2.2.3.RELEASE - 1.3.0 + 1.4.1 2.0.0.RELEASE - 2.2.11.RELEASE - Hoxton.SR8 + 2.4.1 + 2020.0.0 Cairo-SR8 UTF-8 @@ -141,6 +141,11 @@ lombok provided + + org.hibernate.validator + hibernate-validator + 6.2.0.Final + net.dreamlu mica-auto From ef31d33f084d63b59aea79b7b96fcaec9e78b881 Mon Sep 17 00:00:00 2001 From: smallchill Date: Fri, 15 Jan 2021 20:37:59 +0800 Subject: [PATCH 02/20] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96swagger?= =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../swagger/SwaggerAutoConfiguration.java | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerAutoConfiguration.java b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerAutoConfiguration.java index 3a22ef8..31f2123 100644 --- a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerAutoConfiguration.java +++ b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerAutoConfiguration.java @@ -16,7 +16,10 @@ package org.springblade.core.swagger; +import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver; import com.google.common.collect.Lists; +import lombok.AllArgsConstructor; +import org.springblade.core.launch.props.BladeProperties; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -45,12 +48,22 @@ import java.util.List; @EnableSwagger @EnableConfigurationProperties(SwaggerProperties.class) @Import(BeanValidatorPluginsConfiguration.class) +@AllArgsConstructor public class SwaggerAutoConfiguration { - private static final String DEFAULT_MAPPING_PATH = "/"; private static final String DEFAULT_BASE_PATH = "/**"; private static final List DEFAULT_EXCLUDE_PATH = Arrays.asList("/error", "/actuator/**"); + /** + * 引入Knife4j扩展类 + */ + private final OpenApiExtensionResolver openApiExtensionResolver; + + /** + * 引入Blade环境变量 + */ + private final BladeProperties bladeProperties; + @Bean @ConditionalOnMissingBean public SwaggerProperties swaggerProperties() { @@ -77,11 +90,11 @@ public class SwaggerAutoConfiguration { swaggerProperties.getExcludePath().forEach(p -> apis.paths(PathSelectors.ant(p).negate())); return apis.build() - .securitySchemes(Collections.singletonList(securitySchema())) - .securityContexts(Collections.singletonList(securityContext())) - .securityContexts(Lists.newArrayList(securityContext())) - .securitySchemes(Collections.singletonList(securitySchema())) - .pathMapping(DEFAULT_MAPPING_PATH); + .securitySchemes(Collections.singletonList(securitySchema(swaggerProperties))) + .securityContexts(Collections.singletonList(securityContext(swaggerProperties))) + .securityContexts(Lists.newArrayList(securityContext(swaggerProperties))) + .securitySchemes(Collections.singletonList(securitySchema(swaggerProperties))) + .extensions(openApiExtensionResolver.buildExtensions(bladeProperties.getName())); } /** @@ -89,10 +102,10 @@ public class SwaggerAutoConfiguration { * * @return */ - private SecurityContext securityContext() { + private SecurityContext securityContext(SwaggerProperties swaggerProperties) { return SecurityContext.builder() - .securityReferences(defaultAuth()) - .forPaths(PathSelectors.regex(swaggerProperties().getAuthorization().getAuthRegex())) + .securityReferences(defaultAuth(swaggerProperties)) + .forPaths(PathSelectors.regex(swaggerProperties.getAuthorization().getAuthRegex())) .build(); } @@ -101,23 +114,23 @@ public class SwaggerAutoConfiguration { * * @return */ - private List defaultAuth() { + private List defaultAuth(SwaggerProperties swaggerProperties) { ArrayList authorizationScopeList = new ArrayList<>(); - swaggerProperties().getAuthorization().getAuthorizationScopeList().forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription()))); + swaggerProperties.getAuthorization().getAuthorizationScopeList().forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription()))); AuthorizationScope[] authorizationScopes = new AuthorizationScope[authorizationScopeList.size()]; return Collections.singletonList(SecurityReference.builder() - .reference(swaggerProperties().getAuthorization().getName()) + .reference(swaggerProperties.getAuthorization().getName()) .scopes(authorizationScopeList.toArray(authorizationScopes)) .build()); } - private OAuth securitySchema() { + private OAuth securitySchema(SwaggerProperties swaggerProperties) { ArrayList authorizationScopeList = new ArrayList<>(); - swaggerProperties().getAuthorization().getAuthorizationScopeList().forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription()))); + swaggerProperties.getAuthorization().getAuthorizationScopeList().forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription()))); ArrayList grantTypes = new ArrayList<>(); - swaggerProperties().getAuthorization().getTokenUrlList().forEach(tokenUrl -> grantTypes.add(new ResourceOwnerPasswordCredentialsGrant(tokenUrl))); - return new OAuth(swaggerProperties().getAuthorization().getName(), authorizationScopeList, grantTypes); + swaggerProperties.getAuthorization().getTokenUrlList().forEach(tokenUrl -> grantTypes.add(new ResourceOwnerPasswordCredentialsGrant(tokenUrl))); + return new OAuth(swaggerProperties.getAuthorization().getName(), authorizationScopeList, grantTypes); } private ApiInfo apiInfo(SwaggerProperties swaggerProperties) { From f789ef50b536d5b40d0edab8120f4ecc82f5cfa5 Mon Sep 17 00:00:00 2001 From: smallchill Date: Wed, 20 Jan 2021 17:01:11 +0800 Subject: [PATCH 03/20] =?UTF-8?q?:tada:=20=E4=BC=98=E5=8C=96mybatis-plus?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../boot/config/MybatisPlusConfiguration.java | 10 ++++- .../boot/props/MybatisPlusProperties.java | 40 +++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 blade-core-boot/src/main/java/org/springblade/core/boot/props/MybatisPlusProperties.java diff --git a/blade-core-boot/src/main/java/org/springblade/core/boot/config/MybatisPlusConfiguration.java b/blade-core-boot/src/main/java/org/springblade/core/boot/config/MybatisPlusConfiguration.java index ac34e87..0715dca 100644 --- a/blade-core-boot/src/main/java/org/springblade/core/boot/config/MybatisPlusConfiguration.java +++ b/blade-core-boot/src/main/java/org/springblade/core/boot/config/MybatisPlusConfiguration.java @@ -22,9 +22,11 @@ import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerIntercept import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor; import lombok.AllArgsConstructor; import org.mybatis.spring.annotation.MapperScan; +import org.springblade.core.boot.props.MybatisPlusProperties; import org.springblade.core.mp.plugins.SqlLogInterceptor; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -36,6 +38,7 @@ import org.springframework.context.annotation.Configuration; @Configuration(proxyBeanMethods = false) @AllArgsConstructor @MapperScan("org.springblade.**.mapper.**") +@EnableConfigurationProperties(MybatisPlusProperties.class) public class MybatisPlusConfiguration { private final TenantLineHandler tenantLineHandler; @@ -45,12 +48,15 @@ public class MybatisPlusConfiguration { */ @Bean @ConditionalOnMissingBean(MybatisPlusInterceptor.class) - public MybatisPlusInterceptor mybatisPlusInterceptor() { + public MybatisPlusInterceptor mybatisPlusInterceptor(MybatisPlusProperties mybatisPlusProperties) { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); // 配置租户拦截器 interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(tenantLineHandler)); // 配置分页拦截器 - interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); + PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); + paginationInnerInterceptor.setMaxLimit(mybatisPlusProperties.getPageLimit()); + paginationInnerInterceptor.setOverflow(mybatisPlusProperties.getOverflow()); + interceptor.addInnerInterceptor(paginationInnerInterceptor); return interceptor; } diff --git a/blade-core-boot/src/main/java/org/springblade/core/boot/props/MybatisPlusProperties.java b/blade-core-boot/src/main/java/org/springblade/core/boot/props/MybatisPlusProperties.java new file mode 100644 index 0000000..6853135 --- /dev/null +++ b/blade-core-boot/src/main/java/org/springblade/core/boot/props/MybatisPlusProperties.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springblade.core.boot.props; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * MybatisPlus配置类 + * + * @author Chill + */ +@Data +@ConfigurationProperties(prefix = "blade.mybatis-plus") +public class MybatisPlusProperties { + + /** + * 分页最大数 + */ + private Long pageLimit = 500L; + + /** + * 溢出总页数后是否进行处理 + */ + protected Boolean overflow = false; + +} From 1fcf40d917fb7637a15913fd88e7a463b440e355 Mon Sep 17 00:00:00 2001 From: smallchill Date: Thu, 21 Jan 2021 22:17:55 +0800 Subject: [PATCH 04/20] =?UTF-8?q?:tada:=20=E6=9B=B4=E6=96=B0readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 72c87c4..f25f054 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ blade-tool ## 项目地址 * 后端Gitee地址:[https://gitee.com/smallc/SpringBlade](https://gitee.com/smallc/SpringBlade) * 后端Github地址:[https://github.com/chillzhuang/SpringBlade](https://github.com/chillzhuang/SpringBlade) -* 后端SpringBoot版:[https://gitee.com/smallc/SpringBlade/tree/2.0-boot/](https://gitee.com/smallc/SpringBlade/tree/2.0-boot/) +* 后端SpringBoot版:[https://gitee.com/smallc/SpringBlade/tree/boot/](https://gitee.com/smallc/SpringBlade/tree/boot/) * 前端框架Sword(基于React):[https://gitee.com/smallc/Sword](https://gitee.com/smallc/Sword) * 前端框架Saber(基于Vue):[https://gitee.com/smallc/Saber](https://gitee.com/smallc/Saber) * 核心框架项目地址:[https://github.com/chillzhuang/blade-tool](https://github.com/chillzhuang/blade-tool) From d998a37903cd1aad3a56ef7f4f7e2f7adfbd0ffd Mon Sep 17 00:00:00 2001 From: smallchill Date: Mon, 25 Jan 2021 12:30:17 +0800 Subject: [PATCH 05/20] =?UTF-8?q?:tada:=20=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=A2=9E=E5=8A=A0sqlserver=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/springblade/develop/support/BladeCodeGenerator.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/blade-core-develop/src/main/java/org/springblade/develop/support/BladeCodeGenerator.java b/blade-core-develop/src/main/java/org/springblade/develop/support/BladeCodeGenerator.java index ee861b0..b2801eb 100644 --- a/blade-core-develop/src/main/java/org/springblade/develop/support/BladeCodeGenerator.java +++ b/blade-core-develop/src/main/java/org/springblade/develop/support/BladeCodeGenerator.java @@ -25,6 +25,7 @@ import com.baomidou.mybatisplus.generator.config.*; import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert; import com.baomidou.mybatisplus.generator.config.converts.OracleTypeConvert; import com.baomidou.mybatisplus.generator.config.converts.PostgreSqlTypeConvert; +import com.baomidou.mybatisplus.generator.config.converts.SqlServerTypeConvert; import com.baomidou.mybatisplus.generator.config.po.TableInfo; import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; import lombok.Data; @@ -150,6 +151,9 @@ public class BladeCodeGenerator { } else if (StringUtil.containsAny(driverName, DbType.POSTGRE_SQL.getDb())) { dsc.setDbType(DbType.POSTGRE_SQL); dsc.setTypeConvert(new PostgreSqlTypeConvert()); + } else if (StringUtil.containsAny(driverName, DbType.SQL_SERVER.getDb())) { + dsc.setDbType(DbType.SQL_SERVER); + dsc.setTypeConvert(new SqlServerTypeConvert()); } else { dsc.setDbType(DbType.ORACLE); dsc.setTypeConvert(new OracleTypeConvert()); From 40a22619111752841f5614381979425c39da06f7 Mon Sep 17 00:00:00 2001 From: smallchill Date: Sat, 30 Jan 2021 17:29:10 +0800 Subject: [PATCH 06/20] =?UTF-8?q?:tada:=20=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=A2=9E=E5=8A=A0=E8=8F=9C=E5=8D=95id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/templates/sql/menu.sql.vm | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/blade-core-develop/src/main/resources/templates/sql/menu.sql.vm b/blade-core-develop/src/main/resources/templates/sql/menu.sql.vm index 01866c8..25b845b 100644 --- a/blade-core-develop/src/main/resources/templates/sql/menu.sql.vm +++ b/blade-core-develop/src/main/resources/templates/sql/menu.sql.vm @@ -1,11 +1,10 @@ -INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`) -VALUES (0, '$!{cfg.entityKey}', '$!{cfg.codeName}', 'menu', '/$!{cfg.servicePackage}/$!{cfg.entityKey}', NULL, 1, 1, 0, 1, NULL, 0); -set @parentid = (SELECT LAST_INSERT_ID()); -INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`) -VALUES (@parentid, '$!{cfg.entityKey}_add', '新增', 'add', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/add', 'plus', 1, 2, 1, 1, NULL, 0); -INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`) -VALUES (@parentid, '$!{cfg.entityKey}_edit', '修改', 'edit', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/edit', 'form', 2, 2, 1, 2, NULL, 0); -INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`) -VALUES (@parentid, '$!{cfg.entityKey}_delete', '删除', 'delete', '/api/$!{cfg.serviceName}/$!{cfg.entityKey}/remove', 'delete', 3, 2, 1, 3, NULL, 0); -INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`) -VALUES (@parentid, '$!{cfg.entityKey}_view', '查看', 'view', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/view', 'file-text', 4, 2, 1, 2, NULL, 0); +INSERT INTO `blade_menu`(`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`) +VALUES ('$!{cfg.menuId}', 1123598815738675201, '$!{cfg.entityKey}', '$!{cfg.codeName}', 'menu', '/$!{cfg.servicePackage}/$!{cfg.entityKey}', NULL, 1, 1, 0, 1, NULL, 0); +INSERT INTO `blade_menu`(`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`) +VALUES ('$!{cfg.addMenuId}', '$!{cfg.menuId}', '$!{cfg.entityKey}_add', '新增', 'add', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/add', 'plus', 1, 2, 1, 1, NULL, 0); +INSERT INTO `blade_menu`(`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`) +VALUES ('$!{cfg.editMenuId}', '$!{cfg.menuId}', '$!{cfg.entityKey}_edit', '修改', 'edit', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/edit', 'form', 2, 2, 2, 1, NULL, 0); +INSERT INTO `blade_menu`(`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`) +VALUES ('$!{cfg.removeMenuId}', '$!{cfg.menuId}', '$!{cfg.entityKey}_delete', '删除', 'delete', '/api/$!{cfg.serviceName}/$!{cfg.entityKey}/remove', 'delete', 3, 2, 3, 1, NULL, 0); +INSERT INTO `blade_menu`(`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`) +VALUES ('$!{cfg.viewMenuId}', '$!{cfg.menuId}', '$!{cfg.entityKey}_view', '查看', 'view', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/view', 'file-text', 4, 2, 2, 1, NULL, 0); From 60f27fe09afb076e8761acae56cd2c0d07618c84 Mon Sep 17 00:00:00 2001 From: smallchill Date: Sun, 31 Jan 2021 20:41:24 +0800 Subject: [PATCH 07/20] =?UTF-8?q?:tada:=20=E4=BC=98=E5=8C=96SentinelFeign?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E9=80=82=E9=85=8D?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=89=88API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/cloud/feign/BladeFeignSentinel.java | 38 ++++++++----------- .../BladeSentinelInvocationHandler.java | 2 +- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignSentinel.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignSentinel.java index 8427eab..9ef89cf 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignSentinel.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/feign/BladeFeignSentinel.java @@ -24,12 +24,13 @@ import lombok.SneakyThrows; import org.springblade.core.cloud.sentinel.BladeSentinelInvocationHandler; import org.springframework.beans.BeansException; import org.springframework.cloud.openfeign.FallbackFactory; +import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignContext; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.util.ReflectionUtils; +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.util.StringUtils; -import java.lang.reflect.Field; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.util.Map; @@ -46,8 +47,7 @@ public class BladeFeignSentinel { return new Builder(); } - public static final class Builder extends Feign.Builder - implements ApplicationContextAware { + public static final class Builder extends Feign.Builder implements ApplicationContextAware { private Contract contract = new Contract.Default(); private ApplicationContext applicationContext; private FeignContext feignContext; @@ -69,23 +69,26 @@ public class BladeFeignSentinel { super.invocationHandlerFactory(new InvocationHandlerFactory() { @SneakyThrows @Override - public InvocationHandler create(Target target, - Map dispatch) { - Object feignClientFactoryBean = Builder.this.applicationContext.getBean("&" + target.type().getName()); + public InvocationHandler create(Target target, Map dispatch) { + // 注解取值以避免循环依赖的问题 + FeignClient feignClient = AnnotationUtils.findAnnotation(target.type(), FeignClient.class); + Class fallback = feignClient.fallback(); + Class fallbackFactory = feignClient.fallbackFactory(); + String contextId = feignClient.contextId(); - Class fallback = (Class) getFieldValue(feignClientFactoryBean, "fallback"); - Class fallbackFactory = (Class) getFieldValue(feignClientFactoryBean, "fallbackFactory"); - String name = (String) getFieldValue(feignClientFactoryBean, "name"); + if (!StringUtils.hasText(contextId)) { + contextId = feignClient.name(); + } Object fallbackInstance; FallbackFactory fallbackFactoryInstance; // 判断fallback类型 if (void.class != fallback) { - fallbackInstance = getFromContext(name, "fallback", fallback, target.type()); + fallbackInstance = getFromContext(contextId, "fallback", fallback, target.type()); return new BladeSentinelInvocationHandler(target, dispatch, new FallbackFactory.Default(fallbackInstance)); } if (void.class != fallbackFactory) { - fallbackFactoryInstance = (FallbackFactory) getFromContext(name, "fallbackFactory", fallbackFactory, FallbackFactory.class); + fallbackFactoryInstance = (FallbackFactory) getFromContext(contextId, "fallbackFactory", fallbackFactory, FallbackFactory.class); return new BladeSentinelInvocationHandler(target, dispatch, fallbackFactoryInstance); } // 默认fallbackFactory @@ -115,17 +118,6 @@ public class BladeFeignSentinel { return super.build(); } - private Object getFieldValue(Object instance, String fieldName) { - Field field = ReflectionUtils.findField(instance.getClass(), fieldName); - field.setAccessible(true); - try { - return field.get(instance); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - return null; - } - @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/sentinel/BladeSentinelInvocationHandler.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/sentinel/BladeSentinelInvocationHandler.java index b386843..a69ca55 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/sentinel/BladeSentinelInvocationHandler.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/sentinel/BladeSentinelInvocationHandler.java @@ -38,7 +38,7 @@ import java.util.Map; import static feign.Util.checkNotNull; /** - * 重写SentinelInvocationHandler适配最新API + * 重写 {@link com.alibaba.cloud.sentinel.feign.SentinelInvocationHandler} 适配最新API * * @author Chill */ From c0cd574937e92dd72abdac4f740be55d580685db Mon Sep 17 00:00:00 2001 From: smallchill Date: Sun, 31 Jan 2021 20:51:49 +0800 Subject: [PATCH 08/20] =?UTF-8?q?:tada:=203.0.1.RELEASE=20=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E5=8D=87=E7=BA=A7=E9=80=82=E9=85=8D=20SpringCloud=202?= =?UTF-8?q?020.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- blade-core-boot/pom.xml | 2 +- blade-core-boot/src/main/resources/bootstrap.yml | 2 +- blade-core-cloud/pom.xml | 2 +- blade-core-develop/pom.xml | 13 ++++++++++++- blade-core-launch/pom.xml | 2 +- .../core/launch/constant/AppConstant.java | 2 +- blade-core-log/pom.xml | 2 +- blade-core-mybatis/pom.xml | 2 +- blade-core-oss/pom.xml | 2 +- blade-core-report/pom.xml | 2 +- blade-core-secure/pom.xml | 2 +- blade-core-social/pom.xml | 2 +- blade-core-swagger/pom.xml | 2 +- .../springblade/core/swagger/SwaggerProperties.java | 2 +- blade-core-test/pom.xml | 2 +- blade-core-tool/pom.xml | 2 +- blade-core-transaction/pom.xml | 2 +- pom.xml | 13 +++++++------ 19 files changed, 36 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index f25f054..f7684d5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

Build Status Coverage Status - Downloads + Downloads

## SpringBlade微服务开发平台 diff --git a/blade-core-boot/pom.xml b/blade-core-boot/pom.xml index e972551..d7a7a99 100644 --- a/blade-core-boot/pom.xml +++ b/blade-core-boot/pom.xml @@ -5,7 +5,7 @@ org.springblade blade-tool - 3.0.0 + 3.0.1 4.0.0 diff --git a/blade-core-boot/src/main/resources/bootstrap.yml b/blade-core-boot/src/main/resources/bootstrap.yml index 238a42d..3494206 100644 --- a/blade-core-boot/src/main/resources/bootstrap.yml +++ b/blade-core-boot/src/main/resources/bootstrap.yml @@ -97,7 +97,7 @@ mybatis-plus: swagger: title: SpringBlade 接口文档系统 description: SpringBlade 接口文档系统 - version: 3.0.0 + version: 3.0.1 license: Powered By SpringBlade licenseUrl: https://bladex.vip terms-of-service-url: https://bladex.vip diff --git a/blade-core-cloud/pom.xml b/blade-core-cloud/pom.xml index fbbfaa0..69d5f57 100644 --- a/blade-core-cloud/pom.xml +++ b/blade-core-cloud/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.0 + 3.0.1 4.0.0 diff --git a/blade-core-develop/pom.xml b/blade-core-develop/pom.xml index ebbe868..88c030b 100644 --- a/blade-core-develop/pom.xml +++ b/blade-core-develop/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.0 + 3.0.1 4.0.0 @@ -25,6 +25,17 @@ com.baomidou mybatis-plus-generator + ${mybatis.plus.generator.version} + + + com.baomidou + mybatis-plus-extension + + + + + com.baomidou + mybatis-plus-extension ${mybatis.plus.version} diff --git a/blade-core-launch/pom.xml b/blade-core-launch/pom.xml index 991c6b3..9009114 100644 --- a/blade-core-launch/pom.xml +++ b/blade-core-launch/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.0 + 3.0.1 4.0.0 diff --git a/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java b/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java index bcf650a..21d31bd 100644 --- a/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java +++ b/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java @@ -25,7 +25,7 @@ public interface AppConstant { /** * 应用版本 */ - String APPLICATION_VERSION = "3.0.0"; + String APPLICATION_VERSION = "3.0.1"; /** * 基础包 diff --git a/blade-core-log/pom.xml b/blade-core-log/pom.xml index c7582d7..98a2290 100644 --- a/blade-core-log/pom.xml +++ b/blade-core-log/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.0 + 3.0.1 4.0.0 diff --git a/blade-core-mybatis/pom.xml b/blade-core-mybatis/pom.xml index 87301ca..2be41dd 100644 --- a/blade-core-mybatis/pom.xml +++ b/blade-core-mybatis/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.0 + 3.0.1 4.0.0 diff --git a/blade-core-oss/pom.xml b/blade-core-oss/pom.xml index 2da6e65..656557a 100644 --- a/blade-core-oss/pom.xml +++ b/blade-core-oss/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.0 + 3.0.1 4.0.0 diff --git a/blade-core-report/pom.xml b/blade-core-report/pom.xml index 22bd9e6..a97a98d 100644 --- a/blade-core-report/pom.xml +++ b/blade-core-report/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.0 + 3.0.1 4.0.0 diff --git a/blade-core-secure/pom.xml b/blade-core-secure/pom.xml index 9f64081..ac1b1c3 100644 --- a/blade-core-secure/pom.xml +++ b/blade-core-secure/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.0 + 3.0.1 4.0.0 diff --git a/blade-core-social/pom.xml b/blade-core-social/pom.xml index b9cea42..2286c9b 100644 --- a/blade-core-social/pom.xml +++ b/blade-core-social/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.0 + 3.0.1 4.0.0 diff --git a/blade-core-swagger/pom.xml b/blade-core-swagger/pom.xml index f51669f..10ca8a5 100644 --- a/blade-core-swagger/pom.xml +++ b/blade-core-swagger/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.0 + 3.0.1 4.0.0 diff --git a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java index d032e86..0a1d986 100644 --- a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java +++ b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java @@ -55,7 +55,7 @@ public class SwaggerProperties { /** * 版本 **/ - private String version = "3.0.0"; + private String version = "3.0.1"; /** * 许可证 **/ diff --git a/blade-core-test/pom.xml b/blade-core-test/pom.xml index 49a7863..a761306 100644 --- a/blade-core-test/pom.xml +++ b/blade-core-test/pom.xml @@ -5,7 +5,7 @@ org.springblade blade-tool - 3.0.0 + 3.0.1 4.0.0 diff --git a/blade-core-tool/pom.xml b/blade-core-tool/pom.xml index 5d6fc4e..878ae99 100644 --- a/blade-core-tool/pom.xml +++ b/blade-core-tool/pom.xml @@ -6,7 +6,7 @@ org.springblade blade-tool - 3.0.0 + 3.0.1 4.0.0 diff --git a/blade-core-transaction/pom.xml b/blade-core-transaction/pom.xml index 0828955..2ca27e1 100644 --- a/blade-core-transaction/pom.xml +++ b/blade-core-transaction/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.0 + 3.0.1 4.0.0 diff --git a/pom.xml b/pom.xml index 8d90a88..d967362 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springblade blade-tool - 3.0.0 + 3.0.1 pom blade-tool @@ -36,24 +36,25 @@ - 3.0.0 + 3.0.1 1.8 3.8.0 2.10.5 1.6.2 2.0.8 - 3.4.1 + 3.4.2 + 3.4.1 1.6.0 3.4.2 2.3.1 1.2.5 - 2.2.3.RELEASE + 2.2.5.RC2 1.4.1 2.0.0.RELEASE - 2.4.1 - 2020.0.0 + 2.4.2 + 2020.0.1 Cairo-SR8 UTF-8 From 214fd56f0d26ddaf65f320f5243132e7424a0334 Mon Sep 17 00:00:00 2001 From: smallchill Date: Sun, 31 Jan 2021 21:43:23 +0800 Subject: [PATCH 09/20] =?UTF-8?q?:tada:=203.0.1.RELEASE=20=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E5=8D=87=E7=BA=A7=E9=80=82=E9=85=8D=20SpringCloud=202?= =?UTF-8?q?020.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/bootstrap.yml | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/blade-core-boot/src/main/resources/bootstrap.yml b/blade-core-boot/src/main/resources/bootstrap.yml index 3494206..904c514 100644 --- a/blade-core-boot/src/main/resources/bootstrap.yml +++ b/blade-core-boot/src/main/resources/bootstrap.yml @@ -1,32 +1,34 @@ #服务器配置 server: undertow: - # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程 - io-threads: 4 - # 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载 - worker-threads: 20 # 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理 buffer-size: 1024 # 是否分配的直接内存 direct-buffers: true + threads: + # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程 + io: 16 + # 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载 + worker: 400 + servlet: + encoding: + charset: UTF-8 + force: true #spring配置 spring: cache: ehcache: config: classpath:config/ehcache.xml - http: - encoding: - charset: UTF-8 - force: true servlet: multipart: max-file-size: 256MB max-request-size: 1024MB + web: + resources: + add-mappings: false mvc: throw-exception-if-no-handler-found: true - resources: - add-mappings: false datasource: driver-class-name: com.mysql.cj.jdbc.Driver druid: From e22dc339f0f909d4b14dc6d9a89576d0a6848e44 Mon Sep 17 00:00:00 2001 From: smallchill Date: Sun, 31 Jan 2021 21:51:14 +0800 Subject: [PATCH 10/20] =?UTF-8?q?:tada:=203.0.1.RELEASE=20=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E5=8D=87=E7=BA=A7=E9=80=82=E9=85=8D=20SpringCloud=202?= =?UTF-8?q?020.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blade-core-boot/src/main/resources/bootstrap.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/blade-core-boot/src/main/resources/bootstrap.yml b/blade-core-boot/src/main/resources/bootstrap.yml index 904c514..3cfb066 100644 --- a/blade-core-boot/src/main/resources/bootstrap.yml +++ b/blade-core-boot/src/main/resources/bootstrap.yml @@ -5,12 +5,14 @@ server: buffer-size: 1024 # 是否分配的直接内存 direct-buffers: true + # 线程配置 threads: # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程 io: 16 # 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载 worker: 400 servlet: + # 编码配置 encoding: charset: UTF-8 force: true From 81a6b4be1f98514c452f0038a8fd0276470577ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=E5=98=89=E9=98=B3?= Date: Tue, 16 Feb 2021 13:20:41 +0800 Subject: [PATCH 11/20] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=83=E7=89=9B?= =?UTF-8?q?=E4=BA=91=E4=B8=8A=E4=BC=A0=E5=90=8E=E6=97=A0=E6=B3=95=E8=8E=B7?= =?UTF-8?q?=E5=8F=96OriginalName=E4=B8=BA=E7=A9=BA=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/springblade/core/oss/QiniuTemplate.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java b/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java index 46f4c85..c195205 100644 --- a/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java +++ b/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java @@ -158,6 +158,8 @@ public class QiniuTemplate { @SneakyThrows public BladeFile put(String bucketName, InputStream stream, String key, boolean cover) { + BladeFile file = new BladeFile(); + file.setOriginalName(key); makeBucket(bucketName); key = getFileName(key); // 覆盖上传 @@ -172,7 +174,6 @@ public class QiniuTemplate { retry++; } } - BladeFile file = new BladeFile(); file.setName(key); file.setLink(fileLink(bucketName, key)); return file; From ef848ed13c86619560ca436bc4b96b7dd74d1649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=E5=98=89=E9=98=B3?= Date: Sat, 20 Feb 2021 10:29:32 +0800 Subject: [PATCH 12/20] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=B8=83=E7=89=9B=E4=BA=91=E6=96=87=E4=BB=B6=E5=85=AC=E5=BC=80?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E9=93=BE=E6=8E=A5=E5=92=8C=E7=A7=81=E6=9C=89?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springblade/core/oss/QiniuTemplate.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java b/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java index 46f4c85..7304fe0 100644 --- a/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java +++ b/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java @@ -33,6 +33,8 @@ import org.springblade.core.tool.utils.StringPool; import org.springframework.web.multipart.MultipartFile; import java.io.InputStream; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.List; @@ -127,6 +129,33 @@ public class QiniuTemplate { } + /** + * 获取文件公开链接 + * + * @param fileName 文件名 + * @return 文件公开链接 + * @link https://developer.qiniu.com/kodo/1239/java#public-get + */ + public String publicFileLink(String fileName) { + return String.format("%s/%s", ossProperties.getEndpoint(), fileName); + } + + /** + * 获取文件私有链接 + * + * @param fileName 文件名 + * @param expireTime 超时时间 + * @return 私有文件链接 + * @link https://developer.qiniu.com/kodo/1239/java#private-get + */ + @SneakyThrows + public String privateFileLink(String fileName, Long expireTime) { + String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()).replace("+", "%20"); + String publicUrl = String.format("%s/%s", ossProperties.getEndpoint(), encodedFileName); + return auth.privateDownloadUrl(publicUrl, expireTime); + } + + @SneakyThrows public BladeFile putFile(MultipartFile file) { return putFile(ossProperties.getBucketName(), file.getOriginalFilename(), file); From 4e875325ea0110dbf502e0093abde744f52b9c46 Mon Sep 17 00:00:00 2001 From: smallchill Date: Mon, 22 Feb 2021 16:14:52 +0800 Subject: [PATCH 13/20] =?UTF-8?q?:zap:=20=E4=B8=83=E7=89=9Boss=E5=9C=B0?= =?UTF-8?q?=E5=9F=9F=E6=94=B9=E4=B8=BA=E8=87=AA=E5=8A=A8=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/springblade/core/oss/config/QiniuConfiguration.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blade-core-oss/src/main/java/org/springblade/core/oss/config/QiniuConfiguration.java b/blade-core-oss/src/main/java/org/springblade/core/oss/config/QiniuConfiguration.java index ac37297..8bd1b5d 100644 --- a/blade-core-oss/src/main/java/org/springblade/core/oss/config/QiniuConfiguration.java +++ b/blade-core-oss/src/main/java/org/springblade/core/oss/config/QiniuConfiguration.java @@ -52,7 +52,7 @@ public class QiniuConfiguration { @Bean public com.qiniu.storage.Configuration qiniuConfiguration() { - return new com.qiniu.storage.Configuration(Zone.zone0()); + return new com.qiniu.storage.Configuration(Zone.autoZone()); } @Bean @@ -69,7 +69,7 @@ public class QiniuConfiguration { @Bean @ConditionalOnBean(com.qiniu.storage.Configuration.class) public BucketManager bucketManager(com.qiniu.storage.Configuration cfg) { - return new BucketManager(auth(), cfg); + return new BucketManager(Auth.create(ossProperties.getAccessKey(), ossProperties.getSecretKey()), cfg); } @Bean From 99456fe165c4da04fdd8ea2a00c66f2776811873 Mon Sep 17 00:00:00 2001 From: smallchill Date: Mon, 22 Feb 2021 23:01:08 +0800 Subject: [PATCH 14/20] =?UTF-8?q?:arrow=5Fup:=20=E5=8D=87=E7=BA=A7alibaba?= =?UTF-8?q?=20cloud=202.2.5.RELEASE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d967362..98349c0 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ 3.4.2 2.3.1 1.2.5 - 2.2.5.RC2 + 2.2.5.RELEASE 1.4.1 2.0.0.RELEASE From 3bbc662b390fb3abccf30375585aa9a64c0eb9b1 Mon Sep 17 00:00:00 2001 From: smallchill Date: Mon, 22 Feb 2021 23:02:26 +0800 Subject: [PATCH 15/20] =?UTF-8?q?:zap:=20xss=E8=BF=87=E6=BB=A4=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=E9=80=9A=E9=85=8D=E7=AC=A6=E5=8C=B9=E9=85=8D=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springblade/core/tool/support/xss/XssFilter.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/blade-core-tool/src/main/java/org/springblade/core/tool/support/xss/XssFilter.java b/blade-core-tool/src/main/java/org/springblade/core/tool/support/xss/XssFilter.java index cab3e79..80221de 100644 --- a/blade-core-tool/src/main/java/org/springblade/core/tool/support/xss/XssFilter.java +++ b/blade-core-tool/src/main/java/org/springblade/core/tool/support/xss/XssFilter.java @@ -16,7 +16,7 @@ package org.springblade.core.tool.support.xss; import lombok.AllArgsConstructor; -import org.springblade.core.tool.utils.StringPool; +import org.springframework.util.AntPathMatcher; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; @@ -30,8 +30,9 @@ import java.io.IOException; @AllArgsConstructor public class XssFilter implements Filter { - private XssProperties xssProperties; - private XssUrlProperties xssUrlProperties; + private final XssProperties xssProperties; + private final XssUrlProperties xssUrlProperties; + private final AntPathMatcher antPathMatcher = new AntPathMatcher(); @Override public void init(FilterConfig config) { @@ -50,8 +51,8 @@ public class XssFilter implements Filter { } private boolean isSkip(String path) { - return (xssUrlProperties.getExcludePatterns().stream().anyMatch(path::startsWith)) - || (xssProperties.getSkipUrl().stream().map(url -> url.replace("/**", StringPool.EMPTY)).anyMatch(path::startsWith)); + return (xssUrlProperties.getExcludePatterns().stream().anyMatch(pattern -> antPathMatcher.match(pattern, path))) + || (xssProperties.getSkipUrl().stream().anyMatch(pattern -> antPathMatcher.match(pattern, path))); } @Override From c39741d45d359713eac843b83f7777743a86c70e Mon Sep 17 00:00:00 2001 From: smallchill Date: Mon, 22 Feb 2021 23:02:43 +0800 Subject: [PATCH 16/20] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/springblade/core/oss/AliossTemplate.java | 13 ------------- .../org/springblade/core/oss/QiniuTemplate.java | 2 -- .../core/secure/interceptor/ClientInterceptor.java | 4 ++-- .../core/secure/interceptor/SecureInterceptor.java | 4 ++-- 4 files changed, 4 insertions(+), 19 deletions(-) diff --git a/blade-core-oss/src/main/java/org/springblade/core/oss/AliossTemplate.java b/blade-core-oss/src/main/java/org/springblade/core/oss/AliossTemplate.java index a063c16..184b8f8 100644 --- a/blade-core-oss/src/main/java/org/springblade/core/oss/AliossTemplate.java +++ b/blade-core-oss/src/main/java/org/springblade/core/oss/AliossTemplate.java @@ -115,24 +115,11 @@ public class AliossTemplate { return getOssHost(bucketName).concat(StringPool.SLASH).concat(fileName); } - /** - * 文件对象 - * - * @param file 上传文件类 - * @return - */ - @SneakyThrows public BladeFile putFile(MultipartFile file) { return putFile(ossProperties.getBucketName(), file.getOriginalFilename(), file); } - /** - * @param fileName 上传文件名 - * @param file 上传文件类 - * @return - */ - @SneakyThrows public BladeFile putFile(String fileName, MultipartFile file) { return putFile(ossProperties.getBucketName(), fileName, file); diff --git a/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java b/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java index 916b5ed..9c53efe 100644 --- a/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java +++ b/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java @@ -134,7 +134,6 @@ public class QiniuTemplate { * * @param fileName 文件名 * @return 文件公开链接 - * @link https://developer.qiniu.com/kodo/1239/java#public-get */ public String publicFileLink(String fileName) { return String.format("%s/%s", ossProperties.getEndpoint(), fileName); @@ -146,7 +145,6 @@ public class QiniuTemplate { * @param fileName 文件名 * @param expireTime 超时时间 * @return 私有文件链接 - * @link https://developer.qiniu.com/kodo/1239/java#private-get */ @SneakyThrows public String privateFileLink(String fileName, Long expireTime) { diff --git a/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/ClientInterceptor.java b/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/ClientInterceptor.java index 5626bf1..d22fe3f 100644 --- a/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/ClientInterceptor.java +++ b/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/ClientInterceptor.java @@ -26,7 +26,7 @@ import org.springblade.core.tool.jackson.JsonUtil; import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.WebUtil; import org.springframework.http.MediaType; -import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; +import org.springframework.web.servlet.AsyncHandlerInterceptor; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -40,7 +40,7 @@ import java.util.Objects; */ @Slf4j @AllArgsConstructor -public class ClientInterceptor extends HandlerInterceptorAdapter { +public class ClientInterceptor implements AsyncHandlerInterceptor { private final String clientId; diff --git a/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/SecureInterceptor.java b/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/SecureInterceptor.java index 8588a13..74cd559 100644 --- a/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/SecureInterceptor.java +++ b/blade-core-secure/src/main/java/org/springblade/core/secure/interceptor/SecureInterceptor.java @@ -24,7 +24,7 @@ import org.springblade.core.tool.constant.BladeConstant; import org.springblade.core.tool.jackson.JsonUtil; import org.springblade.core.tool.utils.WebUtil; import org.springframework.http.MediaType; -import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; +import org.springframework.web.servlet.AsyncHandlerInterceptor; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -38,7 +38,7 @@ import java.util.Objects; */ @Slf4j @AllArgsConstructor -public class SecureInterceptor extends HandlerInterceptorAdapter { +public class SecureInterceptor implements AsyncHandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { From 9252f24ff0f19b470bd77f69462e3fc604419212 Mon Sep 17 00:00:00 2001 From: smallchill Date: Fri, 26 Feb 2021 15:08:51 +0800 Subject: [PATCH 17/20] =?UTF-8?q?:arrow=5Fup:=20=E5=8D=87=E7=BA=A7=20sprin?= =?UTF-8?q?gboot=20=E8=87=B3=202.4.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f7684d5..830eaed 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

Build Status Coverage Status - Downloads + Downloads

## SpringBlade微服务开发平台 diff --git a/pom.xml b/pom.xml index 98349c0..88cc503 100644 --- a/pom.xml +++ b/pom.xml @@ -53,7 +53,7 @@ 1.4.1 2.0.0.RELEASE - 2.4.2 + 2.4.3 2020.0.1 Cairo-SR8 From bb3d735c3493eb2bb7197f1d686453a491cec982 Mon Sep 17 00:00:00 2001 From: smallchill Date: Sat, 27 Feb 2021 15:42:11 +0800 Subject: [PATCH 18/20] =?UTF-8?q?:zap:=20=E4=BF=AE=E5=A4=8Dfeign=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=A4=B4=E4=BC=A0=E9=80=92=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cloud/config/BladeCloudAutoConfiguration.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/blade-core-cloud/src/main/java/org/springblade/core/cloud/config/BladeCloudAutoConfiguration.java b/blade-core-cloud/src/main/java/org/springblade/core/cloud/config/BladeCloudAutoConfiguration.java index e622088..9f17455 100644 --- a/blade-core-cloud/src/main/java/org/springblade/core/cloud/config/BladeCloudAutoConfiguration.java +++ b/blade-core-cloud/src/main/java/org/springblade/core/cloud/config/BladeCloudAutoConfiguration.java @@ -18,7 +18,9 @@ package org.springblade.core.cloud.config; import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration; import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler; import feign.Feign; +import feign.RequestInterceptor; import org.springblade.core.cloud.feign.BladeFeignSentinel; +import org.springblade.core.cloud.header.BladeFeignRequestHeaderInterceptor; import org.springblade.core.cloud.sentinel.BladeBlockExceptionHandler; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -41,8 +43,8 @@ public class BladeCloudAutoConfiguration { @Scope("prototype") @ConditionalOnMissingBean @ConditionalOnProperty(name = "feign.sentinel.enabled") - public Feign.Builder feignSentinelBuilder() { - return BladeFeignSentinel.builder(); + public Feign.Builder feignSentinelBuilder(RequestInterceptor requestInterceptor) { + return BladeFeignSentinel.builder().requestInterceptor(requestInterceptor); } @Bean @@ -51,4 +53,10 @@ public class BladeCloudAutoConfiguration { return new BladeBlockExceptionHandler(); } + @Bean + @ConditionalOnMissingBean + public RequestInterceptor requestInterceptor() { + return new BladeFeignRequestHeaderInterceptor(); + } + } From 52fc7bb889c8ca32ac5f8a8b788935f83265e734 Mon Sep 17 00:00:00 2001 From: smallchill Date: Sun, 28 Feb 2021 22:27:09 +0800 Subject: [PATCH 19/20] =?UTF-8?q?:arrow=5Fup:=20=E5=8D=87=E7=BA=A7fastjson?= =?UTF-8?q?=E8=87=B31.2.75?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blade-core-cloud/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blade-core-cloud/pom.xml b/blade-core-cloud/pom.xml index 69d5f57..ceef125 100644 --- a/blade-core-cloud/pom.xml +++ b/blade-core-cloud/pom.xml @@ -66,7 +66,7 @@ com.alibaba fastjson - 1.2.74 + 1.2.75 From 2bfa01b5f28925eea1d92430658005e683c82565 Mon Sep 17 00:00:00 2001 From: smallchill Date: Mon, 22 Mar 2021 20:50:41 +0800 Subject: [PATCH 20/20] =?UTF-8?q?:tada:=203.0.2.RELEASE=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20Nacos2.0=20=E9=95=BF=E9=93=BE=E6=8E=A5=E7=89=B9?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- blade-core-boot/pom.xml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- blade-core-cloud/pom.xml | 19 ++++++++++++++++- blade-core-develop/pom.xml | 2 +- blade-core-launch/pom.xml | 2 +- .../core/launch/constant/AppConstant.java | 2 +- blade-core-log/pom.xml | 2 +- blade-core-mybatis/pom.xml | 2 +- blade-core-oss/pom.xml | 2 +- blade-core-report/pom.xml | 2 +- blade-core-secure/pom.xml | 2 +- blade-core-social/pom.xml | 2 +- blade-core-swagger/pom.xml | 2 +- .../core/swagger/SwaggerProperties.java | 2 +- blade-core-test/pom.xml | 2 +- blade-core-tool/pom.xml | 2 +- ...ReadWriteJackson2HttpMessageConverter.java | 2 +- blade-core-transaction/pom.xml | 2 +- pom.xml | 21 +++++++++++++++---- 20 files changed, 53 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 830eaed..13d4946 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

Build Status Coverage Status - Downloads + Downloads

## SpringBlade微服务开发平台 diff --git a/blade-core-boot/pom.xml b/blade-core-boot/pom.xml index d7a7a99..870c29f 100644 --- a/blade-core-boot/pom.xml +++ b/blade-core-boot/pom.xml @@ -5,7 +5,7 @@ org.springblade blade-tool - 3.0.1 + 3.0.2 4.0.0 diff --git a/blade-core-boot/src/main/resources/bootstrap.yml b/blade-core-boot/src/main/resources/bootstrap.yml index 3cfb066..ccfd9e6 100644 --- a/blade-core-boot/src/main/resources/bootstrap.yml +++ b/blade-core-boot/src/main/resources/bootstrap.yml @@ -101,7 +101,7 @@ mybatis-plus: swagger: title: SpringBlade 接口文档系统 description: SpringBlade 接口文档系统 - version: 3.0.1 + version: 3.0.2 license: Powered By SpringBlade licenseUrl: https://bladex.vip terms-of-service-url: https://bladex.vip diff --git a/blade-core-cloud/pom.xml b/blade-core-cloud/pom.xml index ceef125..1b8a51d 100644 --- a/blade-core-cloud/pom.xml +++ b/blade-core-cloud/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.1 + 3.0.2 4.0.0 @@ -49,13 +49,30 @@ com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery + + + com.alibaba.nacos + nacos-client + + ${alibaba.cloud.version} com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config + + + com.alibaba.nacos + nacos-client + + ${alibaba.cloud.version} + + com.alibaba.nacos + nacos-client + ${alibaba.nacos.version} + com.alibaba.cloud diff --git a/blade-core-develop/pom.xml b/blade-core-develop/pom.xml index 88c030b..62f757f 100644 --- a/blade-core-develop/pom.xml +++ b/blade-core-develop/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.1 + 3.0.2 4.0.0 diff --git a/blade-core-launch/pom.xml b/blade-core-launch/pom.xml index 9009114..0ee6527 100644 --- a/blade-core-launch/pom.xml +++ b/blade-core-launch/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.1 + 3.0.2 4.0.0 diff --git a/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java b/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java index 21d31bd..64836b2 100644 --- a/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java +++ b/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java @@ -25,7 +25,7 @@ public interface AppConstant { /** * 应用版本 */ - String APPLICATION_VERSION = "3.0.1"; + String APPLICATION_VERSION = "3.0.2"; /** * 基础包 diff --git a/blade-core-log/pom.xml b/blade-core-log/pom.xml index 98a2290..ab3bf66 100644 --- a/blade-core-log/pom.xml +++ b/blade-core-log/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.1 + 3.0.2 4.0.0 diff --git a/blade-core-mybatis/pom.xml b/blade-core-mybatis/pom.xml index 2be41dd..2d373a8 100644 --- a/blade-core-mybatis/pom.xml +++ b/blade-core-mybatis/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.1 + 3.0.2 4.0.0 diff --git a/blade-core-oss/pom.xml b/blade-core-oss/pom.xml index 656557a..183f74c 100644 --- a/blade-core-oss/pom.xml +++ b/blade-core-oss/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.1 + 3.0.2 4.0.0 diff --git a/blade-core-report/pom.xml b/blade-core-report/pom.xml index a97a98d..7c63ed5 100644 --- a/blade-core-report/pom.xml +++ b/blade-core-report/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.1 + 3.0.2 4.0.0 diff --git a/blade-core-secure/pom.xml b/blade-core-secure/pom.xml index ac1b1c3..9504fc6 100644 --- a/blade-core-secure/pom.xml +++ b/blade-core-secure/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.1 + 3.0.2 4.0.0 diff --git a/blade-core-social/pom.xml b/blade-core-social/pom.xml index 2286c9b..b74867d 100644 --- a/blade-core-social/pom.xml +++ b/blade-core-social/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.1 + 3.0.2 4.0.0 diff --git a/blade-core-swagger/pom.xml b/blade-core-swagger/pom.xml index 10ca8a5..d2f97dd 100644 --- a/blade-core-swagger/pom.xml +++ b/blade-core-swagger/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.1 + 3.0.2 4.0.0 diff --git a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java index 0a1d986..c25f2ad 100644 --- a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java +++ b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java @@ -55,7 +55,7 @@ public class SwaggerProperties { /** * 版本 **/ - private String version = "3.0.1"; + private String version = "3.0.2"; /** * 许可证 **/ diff --git a/blade-core-test/pom.xml b/blade-core-test/pom.xml index a761306..a3e21fe 100644 --- a/blade-core-test/pom.xml +++ b/blade-core-test/pom.xml @@ -5,7 +5,7 @@ org.springblade blade-tool - 3.0.1 + 3.0.2 4.0.0 diff --git a/blade-core-tool/pom.xml b/blade-core-tool/pom.xml index 878ae99..c481bba 100644 --- a/blade-core-tool/pom.xml +++ b/blade-core-tool/pom.xml @@ -6,7 +6,7 @@ org.springblade blade-tool - 3.0.1 + 3.0.2 4.0.0 diff --git a/blade-core-tool/src/main/java/org/springblade/core/tool/jackson/AbstractReadWriteJackson2HttpMessageConverter.java b/blade-core-tool/src/main/java/org/springblade/core/tool/jackson/AbstractReadWriteJackson2HttpMessageConverter.java index cbef009..f41a151 100644 --- a/blade-core-tool/src/main/java/org/springblade/core/tool/jackson/AbstractReadWriteJackson2HttpMessageConverter.java +++ b/blade-core-tool/src/main/java/org/springblade/core/tool/jackson/AbstractReadWriteJackson2HttpMessageConverter.java @@ -82,7 +82,7 @@ public abstract class AbstractReadWriteJackson2HttpMessageConverter extends Abst return false; } AtomicReference causeRef = new AtomicReference<>(); - if (this.objectMapper.canSerialize(clazz, causeRef)) { + if (this.defaultObjectMapper.canSerialize(clazz, causeRef)) { return true; } logWarningIfNecessary(clazz, causeRef.get()); diff --git a/blade-core-transaction/pom.xml b/blade-core-transaction/pom.xml index 2ca27e1..ced11ec 100644 --- a/blade-core-transaction/pom.xml +++ b/blade-core-transaction/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.0.1 + 3.0.2 4.0.0 diff --git a/pom.xml b/pom.xml index 88cc503..c4df877 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springblade blade-tool - 3.0.1 + 3.0.2 pom blade-tool @@ -36,7 +36,7 @@ - 3.0.1 + 3.0.2 1.8 3.8.0 @@ -50,11 +50,12 @@ 2.3.1 1.2.5 2.2.5.RELEASE + 2.0.0 1.4.1 2.0.0.RELEASE - 2.4.3 - 2020.0.1 + 2.4.4 + 2020.0.2 Cairo-SR8 UTF-8 @@ -276,6 +277,18 @@ + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.8 + true + + oss + https://oss.sonatype.org/ + true + +