This is an automated email from the ASF dual-hosted git repository.
moremind 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 6e79c7b7c3 fix:fix local springmvc client cant register success (#6395)
6e79c7b7c3 is described below
commit 6e79c7b7c3f62163d82a7775593de49f95dae754
Author: hengyuss <[email protected]>
AuthorDate: Wed Jun 24 22:47:13 2026 +0800
fix:fix local springmvc client cant register success (#6395)
---
.../client/core/client/AbstractContextRefreshedEventListener.java | 6 +++---
.../client/springmvc/init/SpringMvcClientEventListenerTest.java | 6 ++++--
.../shenyu/client/tars/TarsServiceBeanPostProcessorTest.java | 7 +++++++
3 files changed, 14 insertions(+), 5 deletions(-)
diff --git
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java
index 1aef7389b7..b19ae4e61d 100644
---
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java
+++
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java
@@ -102,8 +102,6 @@ public abstract class
AbstractContextRefreshedEventListener<T, A extends Annotat
private ApplicationContext context;
- private final Boolean isDiscoveryLocalMode;
-
/**
* multiple namespace support.
*/
@@ -138,7 +136,6 @@ public abstract class
AbstractContextRefreshedEventListener<T, A extends Annotat
this.ipAndPort = props.getProperty(ShenyuClientConstants.IP_PORT);
this.host = props.getProperty(ShenyuClientConstants.HOST);
this.port = props.getProperty(ShenyuClientConstants.PORT);
- this.isDiscoveryLocalMode =
Boolean.valueOf(props.getProperty(ShenyuClientConstants.DISCOVERY_LOCAL_MODE_KEY));
publisher.start(shenyuClientRegisterRepository);
}
@@ -152,6 +149,9 @@ public abstract class
AbstractContextRefreshedEventListener<T, A extends Annotat
if (!markRegistered()) {
return;
}
+ String discoveryMode = context.getEnvironment()
+ .getProperty("shenyu.discovery.type",
ShenyuClientConstants.DISCOVERY_LOCAL_MODE);
+ boolean isDiscoveryLocalMode =
ShenyuClientConstants.DISCOVERY_LOCAL_MODE.equals(discoveryMode);
if (isDiscoveryLocalMode) {
List<String> namespaceIds = this.getNamespace();
namespaceIds.forEach(namespaceId ->
publisher.publishEvent(buildURIRegisterDTO(context, beans, namespaceId)));
diff --git
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java
index 33ec3f1066..bfb90dd7e7 100644
---
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java
+++
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java
@@ -95,6 +95,8 @@ public class SpringMvcClientEventListenerTest {
results.put("springMvcClientTestBean3", springMvcClientTestBean3);
results.put("springMvcClientTestBean4", springMvcClientTestBean4);
when(applicationContext.getBeansWithAnnotation(any())).thenReturn(results);
+ when(applicationContext.getEnvironment()).thenReturn(env);
+ when(env.getProperty("shenyu.discovery.type",
ShenyuClientConstants.DISCOVERY_LOCAL_MODE)).thenReturn("local");
contextRefreshedEvent = new ContextRefreshedEvent(applicationContext);
ShenyuClientConfig shenyuClientConfig = mock(ShenyuClientConfig.class);
Assert.assertThrows(ShenyuClientIllegalArgumentException.class, () ->
new SpringMvcClientEventListener(shenyuClientConfig,
mock(ShenyuClientRegisterRepository.class), env));
@@ -199,12 +201,12 @@ public class SpringMvcClientEventListenerTest {
SpringMvcClientEventListener springMvcClientEventListener =
buildSpringMvcClientEventListener(false, false);
Assertions.assertEquals("/order",
springMvcClientEventListener.buildApiSuperPath(
- SpringMvcClientTestBean.class,
AnnotatedElementUtils.findMergedAnnotation(SpringMvcClientTestBean.class,
ShenyuSpringMvcClient.class)), "super-path");
+ SpringMvcClientTestBean.class,
AnnotatedElementUtils.findMergedAnnotation(SpringMvcClientTestBean.class,
ShenyuSpringMvcClient.class)), "super-path");
when(env.getProperty("spring.mvc.servlet.path")).thenReturn("/servlet-path");
when(env.getProperty("server.servlet.context-path")).thenReturn("/servlet-context-path");
Assertions.assertEquals("/servlet-context-path/servlet-path/order",
springMvcClientEventListener.buildApiSuperPath(
- SpringMvcClientTestBean.class,
AnnotatedElementUtils.findMergedAnnotation(SpringMvcClientTestBean.class,
ShenyuSpringMvcClient.class)), "super-path");
+ SpringMvcClientTestBean.class,
AnnotatedElementUtils.findMergedAnnotation(SpringMvcClientTestBean.class,
ShenyuSpringMvcClient.class)), "super-path");
registerUtilsMockedStatic.close();
}
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 26bacfafa9..cb0e3d281d 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
@@ -17,6 +17,7 @@
package org.apache.shenyu.client.tars;
+import org.apache.shenyu.client.core.constant.ShenyuClientConstants;
import
org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException;
import
org.apache.shenyu.client.core.register.ShenyuClientRegisterRepositoryFactory;
import org.apache.shenyu.client.tars.common.annotation.ShenyuTarsClient;
@@ -38,6 +39,7 @@ import org.mockito.MockedStatic;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.core.env.Environment;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -68,6 +70,9 @@ public final class TarsServiceBeanPostProcessorTest {
@Mock
private ApplicationContext applicationContext;
+ @Mock
+ private Environment env;
+
private ContextRefreshedEvent contextRefreshedEvent;
@BeforeEach
@@ -77,6 +82,8 @@ public final class TarsServiceBeanPostProcessorTest {
results.put("tarsDemoService2", tarsDemoService2);
results.put("tarsDemoService3", tarsDemoService3);
when(applicationContext.getBeansWithAnnotation(any())).thenReturn(results);
+ when(applicationContext.getEnvironment()).thenReturn(env);
+ when(env.getProperty("shenyu.discovery.type",
ShenyuClientConstants.DISCOVERY_LOCAL_MODE)).thenReturn("local");
contextRefreshedEvent = new ContextRefreshedEvent(applicationContext);
ShenyuClientConfig shenyuClientConfig = mock(ShenyuClientConfig.class);