From b4ca9bae08fe5ed49fd5e416a28f3174dcccf201 Mon Sep 17 00:00:00 2001 From: Sean Yang Date: Wed, 6 Nov 2024 09:35:40 +0800 Subject: [PATCH] Spring6 compatibility --- dubbo-config/dubbo-config-spring6/pom.xml | 12 +- dubbo-config/pom.xml | 2 - dubbo-dependencies-bom/pom.xml | 6 +- .../tri/rest/support/spring/Helper.java | 32 +++ .../spring/SpringResponseRestFilter.java | 2 +- .../dubbo-spring-boot-3-autoconfigure/pom.xml | 6 +- pom.xml | 205 +++++++++++++++++- 7 files changed, 244 insertions(+), 21 deletions(-) diff --git a/dubbo-config/dubbo-config-spring6/pom.xml b/dubbo-config/dubbo-config-spring6/pom.xml index 673fe767162..520beba17a3 100644 --- a/dubbo-config/dubbo-config-spring6/pom.xml +++ b/dubbo-config/dubbo-config-spring6/pom.xml @@ -28,8 +28,6 @@ 17 17 - 6.1.14 - 3.0.9 @@ -48,22 +46,22 @@ org.springframework spring-beans - ${spring.version} + ${spring-6.version} org.springframework spring-core - ${spring.version} + ${spring-6.version} org.springframework spring-web - ${spring.version} + ${spring-6.version} org.springframework spring-context - ${spring.version} + ${spring-6.version} javax.servlet @@ -74,7 +72,7 @@ org.springframework.boot spring-boot-starter-test - ${spring-boot.version} + ${spring-boot-3.version} test diff --git a/dubbo-config/pom.xml b/dubbo-config/pom.xml index ecfb4322ec3..bc404270a6d 100644 --- a/dubbo-config/pom.xml +++ b/dubbo-config/pom.xml @@ -56,8 +56,6 @@ [17,) - dubbo-config-api - dubbo-config-spring dubbo-config-spring6 diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index a9cdc007d06..25397c73d88 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -90,6 +90,7 @@ 5.3.39 + 2.7.18 5.8.15 3.30.2-GA 1.15.7 @@ -187,7 +188,6 @@ 3.1.9 4.0.2 2.4.0-b180830.0438 - 2.7.18 1.15.1 0.16.0 @@ -259,7 +259,7 @@ org.springframework.boot spring-boot-dependencies - ${spring-boot.version} + ${spring_boot_version} pom import @@ -272,7 +272,7 @@ org.springframework.boot spring-boot-starter-logging - ${spring-boot.version} + ${spring_boot_version} ch.qos.logback diff --git a/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/Helper.java b/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/Helper.java index fd818c06770..26d38cbd61e 100644 --- a/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/Helper.java +++ b/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/Helper.java @@ -19,13 +19,30 @@ import org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta.AnnotationMeta; import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import org.springframework.core.SpringVersion; +import org.springframework.http.ResponseEntity; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.ValueConstants; final class Helper { + public static boolean IS_SPRING_6; + + private static Method getStatusCode; + private static Method value; + private Helper() {} + static { + try { + String version = SpringVersion.getVersion(); + IS_SPRING_6 = StringUtils.hasLength(version) && version.charAt(0) >= '6'; + } catch (Throwable ignored) { + } + } + public static boolean isRequired(AnnotationMeta annotation) { return annotation.getBoolean("required"); } @@ -41,4 +58,19 @@ public static String defaultValue(AnnotationMeta annotation, String public static String defaultValue(String value) { return ValueConstants.DEFAULT_NONE.equals(value) ? null : value; } + + public static int getStatusCode(ResponseEntity entity) { + if (IS_SPRING_6) { + try { + if (getStatusCode == null) { + getStatusCode = ResponseEntity.class.getMethod("getStatusCode"); + value = getStatusCode.getReturnType().getMethod("value"); + } + return (Integer) value.invoke(getStatusCode.invoke(entity)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + return entity.getStatusCode().value(); + } } diff --git a/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/SpringResponseRestFilter.java b/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/SpringResponseRestFilter.java index 05458703c58..f182551087a 100644 --- a/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/SpringResponseRestFilter.java +++ b/dubbo-plugin/dubbo-rest-spring/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/spring/SpringResponseRestFilter.java @@ -87,7 +87,7 @@ public void onResponse(Result result, HttpRequest request, HttpResponse response ResponseEntity entity = (ResponseEntity) value; result.setValue(HttpResult.builder() .body(entity.getBody()) - .status(entity.getStatusCode().value()) + .status(Helper.getStatusCode(entity)) .headers(entity.getHeaders()) .build()); return; diff --git a/dubbo-spring-boot-project/dubbo-spring-boot-3-autoconfigure/pom.xml b/dubbo-spring-boot-project/dubbo-spring-boot-3-autoconfigure/pom.xml index 07ec5b92a4a..feeedbe2b8a 100644 --- a/dubbo-spring-boot-project/dubbo-spring-boot-3-autoconfigure/pom.xml +++ b/dubbo-spring-boot-project/dubbo-spring-boot-3-autoconfigure/pom.xml @@ -28,16 +28,12 @@ jar Apache Dubbo Spring Boot 3 Auto-Configure - - 3.2.1 - - org.springframework.boot spring-boot-dependencies - ${spring-boot.version} + ${spring-boot-3.version} pom import diff --git a/pom.xml b/pom.xml index 02d93df0521..52fc8a66450 100644 --- a/pom.xml +++ b/pom.xml @@ -129,6 +129,7 @@ true true true + check 3.4.2 @@ -148,10 +149,13 @@ 0.6.1 3.0.2 + + 6.1.14 + 3.3.5 + 3.22.3 1.54.0 2.43.0 - check 1.0.0 2.38.0 3.3.2-SNAPSHOT @@ -710,8 +714,6 @@ ${log4j2_version} - - none @@ -982,5 +984,202 @@ dubbo-demo + + spring-6 + + + + org.springframework + spring-aop + ${spring-6.version} + + + org.springframework + spring-aspects + ${spring-6.version} + + + org.springframework + spring-beans + ${spring-6.version} + + + org.springframework + spring-context + ${spring-6.version} + + + org.springframework + spring-context-indexer + ${spring-6.version} + + + org.springframework + spring-context-support + ${spring-6.version} + + + org.springframework + spring-core + ${spring-6.version} + + + org.springframework + spring-core-test + ${spring-6.version} + + + org.springframework + spring-expression + ${spring-6.version} + + + org.springframework + spring-instrument + ${spring-6.version} + + + org.springframework + spring-jcl + ${spring-6.version} + + + org.springframework + spring-jdbc + ${spring-6.version} + + + org.springframework + spring-test + ${spring-6.version} + + + org.springframework + spring-tx + ${spring-6.version} + + + org.springframework + spring-web + ${spring-6.version} + + + org.springframework + spring-webmvc + ${spring-6.version} + + + + + + spring-boot-3 + + 10.1.31 + + + + + org.springframework.boot + spring-boot + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-autoconfigure + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-starter + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-test + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-test-autoconfigure + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-starter-test + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-actuator + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-actuator-autoconfigure + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-starter-actuator + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-configuration-processor + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-starter-aop + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-starter-json + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-starter-log4j2 + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-starter-logging + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-starter-tomcat + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-starter-validation + ${spring-boot-3.version} + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot-3.version} + + + org.apache.tomcat.embed + tomcat-embed-core + ${tomcat.version} + + + org.apache.tomcat.embed + tomcat-embed-el + ${tomcat.version} + + + org.apache.tomcat.embed + tomcat-embed-websocket + ${tomcat.version} + + + +