This is an automated email from the ASF dual-hosted git repository.

jimin pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git


The following commit(s) were added to refs/heads/2.x by this push:
     new dcc7bcec0c optimize: global transaction support non-private methods 
(#7867)
dcc7bcec0c is described below

commit dcc7bcec0cdd537c83eec565515bbdb2b76170f9
Author: jsbxyyx <[email protected]>
AuthorDate: Thu Jan 1 11:38:09 2026 +0800

    optimize: global transaction support non-private methods (#7867)
---
 changes/en-us/2.x.md                               |  1 +
 changes/zh-cn/2.x.md                               |  1 +
 .../GlobalTransactionalInterceptorParser.java      | 18 +++++++++++
 .../GlobalTransactionalInterceptorParserTest.java  | 15 +++++++++
 ...serTest.java => NonPrivateMethodTestClass.java} | 36 ++++++++++++----------
 5 files changed, 54 insertions(+), 17 deletions(-)

diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index 122d0ee009..b15da0d960 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -102,6 +102,7 @@ Add changes here for all PR submitted to the 2.x branch.
 - [[#7822](https://github.com/apache/incubator-seata/pull/7822)] add the 
request and response objects in HTTP thread context
 - [[#7829](https://github.com/apache/incubator-seata/pull/7829)] optimize lz4 
compressor
 - [[#7864](https://github.com/apache/incubator-seata/pull/7864)] automatically 
skip the compilation of console and namingserver modules in JDK<25
+- [[#7867](https://github.com/apache/incubator-seata/pull/7867)] optimize 
global transaction support non-private modifier methods
 - [[#7868](https://github.com/apache/incubator-seata/pull/7868)] change 
build_arm64-binary CI to JDK25 Version and runs on ubuntu-24.04-arm
 - [[#7873](https://github.com/apache/incubator-seata/pull/7873)] upgrade 
jacoco plugin version from 0.8.7 to 0.8.14 in order to adapt JDK25
 - [[#7885](https://github.com/apache/incubator-seata/pull/7885)] replace fury 
with fory
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index 0f3ca8e17c..09379e2543 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -101,6 +101,7 @@
 - [[#7822](https://github.com/apache/incubator-seata/pull/7822)] 在 HTTP 
线程上下文中添加请求和响应对象
 - [[#7829](https://github.com/apache/incubator-seata/pull/7829)] 优化lz4 
compressor
 - [[#7864](https://github.com/apache/incubator-seata/pull/7864)] 
自动跳过JDK<25环境下的console和namingserver模块编译
+- [[#7867](https://github.com/apache/incubator-seata/pull/7867)] 
优化全局事务注解支持非private修饰符方法
 - [[#7868](https://github.com/apache/incubator-seata/pull/7868)] 
将build_arm64-binary的CI更改为JDK25版本,并运行于ubuntu-24.04-arm
 - [[#7873](https://github.com/apache/incubator-seata/pull/7873)] 
将Jacoco插件版本从0.8.7升级到0.8.14以适配JDK25
 - [[#7885](https://github.com/apache/incubator-seata/pull/7885)] 替换 fury 至 fory
diff --git 
a/integration-tx-api/src/main/java/org/apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
 
b/integration-tx-api/src/main/java/org/apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
index f5fe2303eb..67c3088a95 100644
--- 
a/integration-tx-api/src/main/java/org/apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
+++ 
b/integration-tx-api/src/main/java/org/apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParser.java
@@ -28,6 +28,7 @@ import org.apache.seata.spring.annotation.GlobalTransactional;
 import org.apache.seata.tm.api.FailureHandlerHolder;
 
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -96,6 +97,23 @@ public class GlobalTransactionalInterceptorParser implements 
InterfaceParser {
                         result = true;
                     }
 
+                    GlobalLock lockAnno = 
method.getAnnotation(GlobalLock.class);
+                    if (lockAnno != null) {
+                        methodsToProxy.add(method.getName());
+                        result = true;
+                    }
+                }
+                Method[] declaredMethods = clazz.getDeclaredMethods();
+                for (Method method : declaredMethods) {
+                    if (Modifier.isPrivate(method.getModifiers())) {
+                        continue;
+                    }
+                    trxAnno = method.getAnnotation(GlobalTransactional.class);
+                    if (trxAnno != null) {
+                        methodsToProxy.add(method.getName());
+                        result = true;
+                    }
+
                     GlobalLock lockAnno = 
method.getAnnotation(GlobalLock.class);
                     if (lockAnno != null) {
                         methodsToProxy.add(method.getName());
diff --git 
a/integration-tx-api/src/test/java/org/apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParserTest.java
 
b/integration-tx-api/src/test/java/org/apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParserTest.java
index e3733ff8d4..191e14ef4c 100644
--- 
a/integration-tx-api/src/test/java/org/apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParserTest.java
+++ 
b/integration-tx-api/src/test/java/org/apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParserTest.java
@@ -38,4 +38,19 @@ public class GlobalTransactionalInterceptorParserTest {
         // then
         Assertions.assertNotNull(proxyInvocationHandler);
     }
+
+    @Test
+    void shouldProxyOnlyNonPrivateMethods() throws Exception {
+        NonPrivateMethodTestClass testClass = new NonPrivateMethodTestClass();
+
+        GlobalTransactionalInterceptorParser 
globalTransactionalInterceptorParser =
+                new GlobalTransactionalInterceptorParser();
+
+        ProxyInvocationHandler proxyInvocationHandler = 
globalTransactionalInterceptorParser.parserInterfaceToProxy(
+                testClass, testClass.getClass().getName());
+
+        Assertions.assertNotNull(proxyInvocationHandler);
+
+        Assertions.assertEquals(2, 
proxyInvocationHandler.getMethodsToProxy().size());
+    }
 }
diff --git 
a/integration-tx-api/src/test/java/org/apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParserTest.java
 
b/integration-tx-api/src/test/java/org/apache/seata/integration/tx/api/interceptor/parser/NonPrivateMethodTestClass.java
similarity index 53%
copy from 
integration-tx-api/src/test/java/org/apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParserTest.java
copy to 
integration-tx-api/src/test/java/org/apache/seata/integration/tx/api/interceptor/parser/NonPrivateMethodTestClass.java
index e3733ff8d4..1033688c34 100644
--- 
a/integration-tx-api/src/test/java/org/apache/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParserTest.java
+++ 
b/integration-tx-api/src/test/java/org/apache/seata/integration/tx/api/interceptor/parser/NonPrivateMethodTestClass.java
@@ -16,26 +16,28 @@
  */
 package org.apache.seata.integration.tx.api.interceptor.parser;
 
-import 
org.apache.seata.integration.tx.api.interceptor.handler.ProxyInvocationHandler;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
+import org.apache.seata.spring.annotation.GlobalTransactional;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-public class GlobalTransactionalInterceptorParserTest {
+public class NonPrivateMethodTestClass {
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(NonPrivateMethodTestClass.class);
 
-    @Test
-    void parserInterfaceToProxy() throws Exception {
-
-        // given
-        BusinessImpl business = new BusinessImpl();
-
-        GlobalTransactionalInterceptorParser 
globalTransactionalInterceptorParser =
-                new GlobalTransactionalInterceptorParser();
+    @GlobalTransactional(timeoutMills = 300000)
+    String defaultMethod() {
+        LOGGER.info("default method");
+        return "default method";
+    }
 
-        // when
-        ProxyInvocationHandler proxyInvocationHandler = 
globalTransactionalInterceptorParser.parserInterfaceToProxy(
-                business, business.getClass().getName());
+    @GlobalTransactional(timeoutMills = 300000)
+    protected String protectedMethod() {
+        LOGGER.info("protected method");
+        return "protected method";
+    }
 
-        // then
-        Assertions.assertNotNull(proxyInvocationHandler);
+    @GlobalTransactional(timeoutMills = 300000)
+    private String privateMethod() {
+        LOGGER.info("private method");
+        return "private method";
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to