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

Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new f2ef750880 [type:fix] resolve the tars service annotation the same way 
the bean lookup does (#6790) (#7213)
f2ef750880 is described below

commit f2ef7508802f1b8d038ff06262144acc150f0823
Author: HY-love-sleep <[email protected]>
AuthorDate: Sat Sep 26 13:09:24 2026 +0800

    [type:fix] resolve the tars service annotation the same way the bean lookup 
does (#6790) (#7213)
    
    Co-authored-by: aias00 <[email protected]>
---
 .../client/tars/TarsServiceBeanEventListener.java  |  5 +++-
 .../tars/TarsServiceBeanPostProcessorTest.java     | 27 ++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git 
a/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/TarsServiceBeanEventListener.java
 
b/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/TarsServiceBeanEventListener.java
index 59891e1a79..917a7ade96 100644
--- 
a/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/TarsServiceBeanEventListener.java
+++ 
b/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/TarsServiceBeanEventListener.java
@@ -166,7 +166,10 @@ public class TarsServiceBeanEventListener extends 
AbstractContextRefreshedEventL
                                                 @NonNull final 
ShenyuTarsClient shenyuTarsClient,
                                                 final String path, final 
Class<?> clazz,
                                                 final Method method, final 
String namespaceId) {
-        String serviceName = 
clazz.getAnnotation(ShenyuTarsService.class).serviceName();
+        // the annotation may be declared on an interface or a superclass - 
the bean lookup above
+        // finds those, so resolve the annotation the same way instead of 
using plain reflection
+        ShenyuTarsService shenyuTarsService = 
AnnotatedElementUtils.findMergedAnnotation(clazz, ShenyuTarsService.class);
+        String serviceName = Objects.isNull(shenyuTarsService) ? 
StringUtils.EMPTY : shenyuTarsService.serviceName();
         String ipAndPort = this.ipAndPort;
         String desc = shenyuTarsClient.desc();
         String configRuleName = shenyuTarsClient.ruleName();
diff --git 
a/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java
 
b/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java
index cb0e3d281d..dd4a338dcb 100644
--- 
a/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java
+++ 
b/shenyu-client/shenyu-client-tars/src/test/java/org/apache/shenyu/client/tars/TarsServiceBeanPostProcessorTest.java
@@ -67,6 +67,8 @@ public final class TarsServiceBeanPostProcessorTest {
 
     private final TarsDemoService3 tarsDemoService3 = new TarsDemoService3();
 
+    private final TarsInterfaceServiceImpl tarsInterfaceServiceImpl = new 
TarsInterfaceServiceImpl();
+
     @Mock
     private ApplicationContext applicationContext;
 
@@ -81,6 +83,7 @@ public final class TarsServiceBeanPostProcessorTest {
         results.put("tarsDemoService", tarsDemoService);
         results.put("tarsDemoService2", tarsDemoService2);
         results.put("tarsDemoService3", tarsDemoService3);
+        results.put("tarsInterfaceService", tarsInterfaceServiceImpl);
         
when(applicationContext.getBeansWithAnnotation(any())).thenReturn(results);
         when(applicationContext.getEnvironment()).thenReturn(env);
         when(env.getProperty("shenyu.discovery.type", 
ShenyuClientConstants.DISCOVERY_LOCAL_MODE)).thenReturn("local");
@@ -131,6 +134,30 @@ public final class TarsServiceBeanPostProcessorTest {
         return new TarsServiceBeanEventListener(clientConfig, 
ShenyuClientRegisterRepositoryFactory.newInstance(mockRegisterCenter));
     }
 
+    @Test
+    public void testPostProcessServantAnnotatedOnInterface() {
+        registerUtilsMockedStatic.when(() -> RegisterUtils.doLogin(any(), 
any(), any())).thenReturn(Optional.of("token"));
+        TarsServiceBeanEventListener tarsServiceBeanEventListener = 
buildTarsServiceBeanEventListener(true);
+        tarsServiceBeanEventListener.onApplicationEvent(contextRefreshedEvent);
+        verify(applicationContext, times(2)).getBeansWithAnnotation(any());
+        registerUtilsMockedStatic.close();
+    }
+
+    @ShenyuTarsService(serviceName = "ifaceService")
+    interface TarsInterfaceService {
+
+        String hello(String hello);
+    }
+
+    static class TarsInterfaceServiceImpl implements TarsInterfaceService {
+
+        @Override
+        @ShenyuTarsClient("ifaceHello")
+        public String hello(final String hello) {
+            return hello;
+        }
+    }
+
     @ShenyuTarsService(serviceName = "testObj")
     static class TarsDemoService {
         @ShenyuTarsClient("hello")

Reply via email to