Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring6 compatibility #14866

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions dubbo-config/dubbo-config-spring6/pom.xml
Original file line number Diff line number Diff line change
@@ -28,8 +28,6 @@
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<spring.version>6.1.14</spring.version>
<spring-boot.version>3.0.9</spring-boot.version>
</properties>

<dependencies>
@@ -48,22 +46,22 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
@@ -74,7 +72,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version>
<version>${spring-boot-3.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
2 changes: 0 additions & 2 deletions dubbo-config/pom.xml
Original file line number Diff line number Diff line change
@@ -56,8 +56,6 @@
<jdk>[17,)</jdk>
</activation>
<modules>
<module>dubbo-config-api</module>
<module>dubbo-config-spring</module>
<module>dubbo-config-spring6</module>
</modules>
</profile>
6 changes: 3 additions & 3 deletions dubbo-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
@@ -90,6 +90,7 @@
<!-- Common libs -->
<!-- <spring_version>4.3.30.RELEASE</spring_version> -->
<spring_version>5.3.39</spring_version>
<spring_boot_version>2.7.18</spring_boot_version>
<spring_security_version>5.8.15</spring_security_version>
<javassist_version>3.30.2-GA</javassist_version>
<byte-buddy_version>1.15.7</byte-buddy_version>
@@ -187,7 +188,6 @@
<open_feign_version>3.1.9</open_feign_version>
<jakarta.xml.bind-api.version>4.0.2</jakarta.xml.bind-api.version>
<jaxb-runtime.version>2.4.0-b180830.0438</jaxb-runtime.version>
<spring-boot.version>2.7.18</spring-boot.version>
<!-- Spring boot buddy is lower than the delivery dependency package version and can only show the defined dependency version -->
<byte-buddy.version>1.15.1</byte-buddy.version>
<prometheus-client.version>0.16.0</prometheus-client.version>
@@ -259,7 +259,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<version>${spring_boot_version}</version>
<type>pom</type>
<scope>import</scope>
<exclusions>
@@ -272,7 +272,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<version>${spring-boot.version}</version>
<version>${spring_boot_version}</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
Original file line number Diff line number Diff line change
@@ -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> annotation) {
return annotation.getBoolean("required");
}
@@ -41,4 +58,19 @@ public static String defaultValue(AnnotationMeta<Annotation> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -28,16 +28,12 @@
<packaging>jar</packaging>
<description>Apache Dubbo Spring Boot 3 Auto-Configure</description>

<properties>
<spring-boot.version>3.2.1</spring-boot.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<version>${spring-boot-3.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Loading