Skip to content

Commit

Permalink
Spring6 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
oxsean committed Nov 6, 2024
1 parent 5239ded commit d8513bb
Show file tree
Hide file tree
Showing 7 changed files with 241 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.7</byte-buddy_version>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,27 @@
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 {
String version = SpringVersion.getVersion();
IS_SPRING_6 = StringUtils.hasLength(version) && version.charAt(0) >= '6';
}

public static boolean isRequired(AnnotationMeta<Annotation> annotation) {
return annotation.getBoolean("required");
}
Expand All @@ -41,4 +55,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
205 changes: 202 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<checkstyle_unix.skip>true</checkstyle_unix.skip>
<rat.skip>true</rat.skip>
<jacoco.skip>true</jacoco.skip>
<spotless.action>check</spotless.action>

<!-- Maven plugins -->
<maven_jar_version>3.4.2</maven_jar_version>
Expand All @@ -148,10 +149,13 @@
<maven_protobuf_plugin_version>0.6.1</maven_protobuf_plugin_version>
<maven_gmavenplus.version>3.0.2</maven_gmavenplus.version>

<!-- For unify spring boot 3 version -->
<spring-6.version>6.1.14</spring-6.version>
<spring-boot-3.version>3.3.5</spring-boot-3.version>

<protobuf-protoc_version>3.22.3</protobuf-protoc_version>
<grpc_version>1.54.0</grpc_version>
<spotless-maven-plugin.version>2.43.0</spotless-maven-plugin.version>
<spotless.action>check</spotless.action>
<dubbo-shared-resources.version>1.0.0</dubbo-shared-resources.version>
<palantirJavaFormat.version>2.38.0</palantirJavaFormat.version>
<revision>3.3.2-SNAPSHOT</revision>
Expand Down Expand Up @@ -710,8 +714,6 @@
<version>${log4j2_version}</version>
</additionalDependency>
</additionalDependencies>
<!--FIXME-->
<!--<doclint>all,-missing</doclint>-->
<doclint>none</doclint>
</configuration>
</execution>
Expand Down Expand Up @@ -982,5 +984,202 @@
<module>dubbo-demo</module>
</modules>
</profile>
<profile>
<id>spring-6</id>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-indexer</artifactId>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core-test</artifactId>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jcl</artifactId>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring-6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-6.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
<profile>
<id>spring-boot-3</id>
<properties>
<tomcat.version>10.1.31</tomcat.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test-autoconfigure</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot-3.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>${tomcat.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
</profiles>
</project>

0 comments on commit d8513bb

Please sign in to comment.