Skip to content

Commit

Permalink
optimize: First support spring:6.x and spring-boot:3.x (apache#5115)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed Dec 18, 2022
1 parent fad95fe commit d07516b
Show file tree
Hide file tree
Showing 24 changed files with 509 additions and 57 deletions.
43 changes: 35 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [ test*, "*.*.*" ]

jobs:
# job 1
test:
name: "test"
runs-on: ubuntu-latest
Expand All @@ -13,8 +14,8 @@ jobs:
matrix:
java: [ 8, 11, 17 ]
springboot: [
2.7.2 -Dspring-framework.version=5.3.22,
2.6.10 -Dspring-framework.version=5.3.22,
2.7.6 -Dspring-framework.version=5.3.24,
2.6.14 -Dspring-framework.version=5.3.24,
2.5.14 -Dspring-framework.version=5.3.20,
2.4.13 -Dspring-framework.version=5.3.13,
2.3.12.RELEASE -Dspring-framework.version=5.2.15.RELEASE,
Expand All @@ -32,14 +33,12 @@ jobs:
# step 1
- name: "Checkout"
uses: actions/checkout@v2.4.0

# step 2
- name: "Set up Java JDK"
uses: actions/setup-java@v2.5.0
with:
distribution: 'zulu'
java-version: ${{ matrix.java }}

# step 3
- name: "Test with Maven"
# https://docs.github.com/cn/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions#github-context
Expand All @@ -49,14 +48,42 @@ jobs:
else
./mvnw -T 4C clean test -Dspring-boot.version=${{ matrix.springboot }} -Dcheckstyle.skip=true -Dlicense.skip=true -e -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn;
fi
arm64-test:
# job 2
test-springboot3x:
name: "test-springboot3.x"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
java: [ 17 ]
springboot: [
3.0.0 -Dspring-framework.version=6.0.2 -Dspring-boot-for-server.version=2.4.13 -Dspring-framework-for-server.version=5.3.18 -Dkotlin-maven-plugin.version=1.7.22
]
steps:
# step 1
- name: "Checkout"
uses: actions/checkout@v2.4.0
# step 2
- name: "Set up Java JDK"
uses: actions/setup-java@v2.5.0
with:
distribution: 'zulu'
java-version: ${{ matrix.java }}
# step 3
- name: "Test with Maven"
run: |
./mvnw -T 4C clean test -Dspring-boot.version=${{ matrix.springboot }} -Dcheckstyle.skip=false -Dlicense.skip=false -e -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn;
# job 3
arm64-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
springboot: [
2.7.2 -Dspring-framework.version=5.3.22,
2.6.10 -Dspring-framework.version=5.3.22,
2.7.6 -Dspring-framework.version=5.3.24,
2.6.14 -Dspring-framework.version=5.3.24,
2.5.14 -Dspring-framework.version=5.3.20,
2.4.13 -Dspring-framework.version=5.3.13,
2.3.12.RELEASE -Dspring-framework.version=5.2.15.RELEASE,
Expand All @@ -69,7 +96,7 @@ jobs:
#1.2.8.RELEASE,
#1.1.12.RELEASE,
#1.0.2.RELEASE
]
]
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
Expand Down
5 changes: 5 additions & 0 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@
<artifactId>seata-http</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-http-jakarta</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-dubbo-alibaba</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion changes/en-us/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Add changes here for all PR submitted to the develop branch.
- [[#xxx](https://github.com/seata/seata/pull/xxx)] fix xxx

### optimize:
- [[#xxx](https://github.com/seata/seata/pull/xxx)] optimize xxx
- [[#5115](https://github.com/seata/seata/pull/5115)] compatible with the `spring-boot:3.x`

### test:
- [[#xxx](https://github.com/seata/seata/pull/xxx)] add test for xxx
Expand All @@ -18,5 +18,6 @@ Thanks to these contributors for their code commits. Please report an unintended

<!-- Please make sure your Github ID is in the list below -->
- [slievrly](https://github.com/slievrly)
- [wangliang181230](https://github.com/wangliang181230)

Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
5 changes: 3 additions & 2 deletions changes/zh-cn/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
### bugfix:
- [[#xxx](https://github.com/seata/seata/pull/xxx)] 修复 xxx

### optimize:
- [[#xxx](https://github.com/seata/seata/pull/xxx)] 优化 xxx
### optimize
- [[#5115](https://github.com/seata/seata/pull/5115)] 兼容 `spring-boot:3.x`

### test:
- [[#xxx](https://github.com/seata/seata/pull/xxx)] 增加 xxx 测试
Expand All @@ -18,5 +18,6 @@

<!-- 请确保您的 GitHub ID 在以下列表中 -->
- [slievrly](https://github.com/slievrly)
- [wangliang181230](https://github.com/wangliang181230)

同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
33 changes: 33 additions & 0 deletions console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,39 @@
<name>seata-console ${project.version}</name>
<description>console for Seata built with Maven</description>

<properties>
<spring-boot-for-server.version>${spring-boot.version}</spring-boot-for-server.version>
<spring-framework-for-server.version>${spring-framework.version}</spring-framework-for-server.version>
</properties>

<dependencyManagement>
<dependencies>
<!-- spring-framework-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${spring-framework-for-server.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<!-- spring-boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot-for-server.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
</exclusion>
</exclusions>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
18 changes: 18 additions & 0 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
<testcontainers.version>1.11.2</testcontainers.version>
<guava.version>27.0.1-jre</guava.version>
<javax-inject.version>1</javax-inject.version>
<javax.annotation-api.version>1.3.2</javax.annotation-api.version>
<javax.servlet-api.version>4.0.1</javax.servlet-api.version>
<jakarta.servlet-api.version>5.0.0</jakarta.servlet-api.version>
<archaius-core.version>0.7.6</archaius-core.version>
<sofa.registry.version>5.2.0</sofa.registry.version>
<motan.version>1.0.0</motan.version>
Expand Down Expand Up @@ -423,6 +426,21 @@
<artifactId>javax.inject</artifactId>
<version>${javax-inject.version}</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax.annotation-api.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet-api.version}</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>${jakarta.servlet-api.version}</version>
</dependency>
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-core</artifactId>
Expand Down
51 changes: 51 additions & 0 deletions integration/http-jakarta/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 1999-2019 Seata.io Group.
~
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.seata</groupId>
<artifactId>seata-parent</artifactId>
<version>${revision}</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>seata-http-jakarta</artifactId>
<packaging>jar</packaging>
<name>seata-http ${project.version}</name>
<description>http-client integration for Seata built with Maven</description>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-http</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* 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 io.seata.integration.http;

import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

/**
* The Jakarta Seata Web Mvc Configurer
*
* @author wang.liang
*/
public class JakartaSeataWebMvcConfigurer extends SeataWebMvcConfigurer {

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new JakartaTransactionPropagationInterceptor());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* 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 io.seata.integration.http;

import io.seata.core.context.RootContext;

/**
* The Jakarta SpringMVC Interceptor.
*
* @author wangxb
* @author wang.liang
*/
public class JakartaTransactionPropagationInterceptor extends TransactionPropagationInterceptor {

//@Override
public boolean preHandle(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Object handler) {
String rpcXid = request.getHeader(RootContext.KEY_XID);
return this.bindXid(rpcXid);
}

//@Override
public void afterCompletion(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Object handler, Exception ex) throws Exception {
if (RootContext.inGlobalTransaction()) {
String rpcXid = request.getHeader(RootContext.KEY_XID);
this.cleanXid(rpcXid);
}
}
}
6 changes: 6 additions & 0 deletions integration/http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@
*/
package io.seata.integration.http;

import io.seata.core.context.RootContext;
import org.springframework.lang.Nullable;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Http exception handle.
* The Handler Interceptor Adapter
*
* @author wangxb
* @author wang.liang
*/
public class HttpHandlerExceptionResolver extends AbstractHandlerExceptionResolver {
public interface HandlerInterceptorAdapter extends HandlerInterceptor {

default boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
return true;
}

@Override
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse httpServletResponse, Object o, Exception e) {
default void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
}

XidResource.cleanXid(request.getHeader(RootContext.KEY_XID));
return null;
default void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
}
}
Loading

0 comments on commit d07516b

Please sign in to comment.