Skip to content

Commit

Permalink
Spring6 compatibility (#14866)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxsean authored Nov 13, 2024
1 parent 59663c8 commit 8bfbb58
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 21 deletions.
12 changes: 5 additions & 7 deletions dubbo-config/dubbo-config-spring6/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down
2 changes: 0 additions & 2 deletions dubbo-config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 3 additions & 3 deletions dubbo-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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.10</byte-buddy_version>
Expand Down Expand Up @@ -188,7 +189,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>
Expand Down Expand Up @@ -260,7 +260,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>
Expand All @@ -273,7 +273,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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Loading

0 comments on commit 8bfbb58

Please sign in to comment.