This is an automated email from the ASF dual-hosted git repository.
liuhongyu 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 134b48df1a [type:fix] Fix the nacos data sync model missing the
contextPath configuration (#5721) (#5722)
134b48df1a is described below
commit 134b48df1a047705e0058e5b798393d08cffb068
Author: Wweiei <[email protected]>
AuthorDate: Thu Oct 31 12:10:25 2024 +0800
[type:fix] Fix the nacos data sync model missing the contextPath
configuration (#5721) (#5722)
* add nacosConfig contextPath param
* config shenyu.sync.nacos.context-path default value: nacos
---------
Co-authored-by: aias00 <[email protected]>
Co-authored-by: xiaoyu <[email protected]>
Co-authored-by: moremind <[email protected]>
---
.../admin/config/NacosSyncConfiguration.java | 3 +++
.../admin/config/properties/NacosProperties.java | 20 +++++++++++++++++
shenyu-admin/src/main/resources/application.yml | 1 +
.../src/main/resources/application.yml | 1 +
.../data/nacos/NacosSyncDataConfiguration.java | 3 +++
.../shenyu/sync/data/nacos/config/NacosConfig.java | 26 +++++++++++++++++++++-
.../sync/data/nacos/config/NacosConfigTest.java | 7 +++++-
7 files changed, 59 insertions(+), 2 deletions(-)
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-nacos/src/main/java/org/apache/shenyu/admin/config/NacosSyncConfiguration.java
b/shenyu-admin-listener/shenyu-admin-listener-nacos/src/main/java/org/apache/shenyu/admin/config/NacosSyncConfiguration.java
index d4ccbd970b..f5cf0bb332 100644
---
a/shenyu-admin-listener/shenyu-admin-listener-nacos/src/main/java/org/apache/shenyu/admin/config/NacosSyncConfiguration.java
+++
b/shenyu-admin-listener/shenyu-admin-listener-nacos/src/main/java/org/apache/shenyu/admin/config/NacosSyncConfiguration.java
@@ -72,6 +72,9 @@ public class NacosSyncConfiguration {
if (StringUtils.isNotBlank(nacosProp.getPassword())) {
properties.put(PropertyKeyConst.PASSWORD,
nacosProp.getPassword());
}
+ if (StringUtils.isNotBlank(nacosProp.getContextPath())) {
+ properties.put(PropertyKeyConst.CONTEXT_PATH,
nacosProp.getContextPath());
+ }
}
return NacosFactory.createConfigService(properties);
}
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-nacos/src/main/java/org/apache/shenyu/admin/config/properties/NacosProperties.java
b/shenyu-admin-listener/shenyu-admin-listener-nacos/src/main/java/org/apache/shenyu/admin/config/properties/NacosProperties.java
index 8ad8939f54..3e131ee3fc 100644
---
a/shenyu-admin-listener/shenyu-admin-listener-nacos/src/main/java/org/apache/shenyu/admin/config/properties/NacosProperties.java
+++
b/shenyu-admin-listener/shenyu-admin-listener-nacos/src/main/java/org/apache/shenyu/admin/config/properties/NacosProperties.java
@@ -33,6 +33,8 @@ public class NacosProperties {
private String password;
+ private String contextPath;
+
private NacosACMProperties acm;
/**
@@ -107,6 +109,24 @@ public class NacosProperties {
this.password = password;
}
+ /**
+ * Gets the value of contextPath.
+ *
+ * @return the value of contextPath
+ */
+ public String getContextPath() {
+ return contextPath;
+ }
+
+ /**
+ * Sets the contextPath.
+ *
+ * @param contextPath contextPath
+ */
+ public void setContextPath(final String contextPath) {
+ this.contextPath = contextPath;
+ }
+
/**
* Gets the value of acm.
*
diff --git a/shenyu-admin/src/main/resources/application.yml
b/shenyu-admin/src/main/resources/application.yml
index 3b61a348de..49f986d23e 100755
--- a/shenyu-admin/src/main/resources/application.yml
+++ b/shenyu-admin/src/main/resources/application.yml
@@ -90,6 +90,7 @@ shenyu:
# namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
# username:
# password:
+# context-path: nacos
# acm:
# enabled: false
# endpoint: acm.aliyun.com
diff --git a/shenyu-bootstrap/src/main/resources/application.yml
b/shenyu-bootstrap/src/main/resources/application.yml
index 70b19fa10d..18fbbf7880 100644
--- a/shenyu-bootstrap/src/main/resources/application.yml
+++ b/shenyu-bootstrap/src/main/resources/application.yml
@@ -253,6 +253,7 @@ shenyu:
# namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
# username:
# password:
+# context-path: nacos
# acm:
# enabled: false
# endpoint: acm.aliyun.com
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-nacos/src/main/java/org/apache/shenyu/springboot/starter/sync/data/nacos/NacosSyncDataConfiguration.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-nacos/src/main/java/org/apache/shenyu/springboot/starter/sync/data/nacos/NacosSyncDataConfiguration.java
index bcdd667575..4486cf5f30 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-nacos/src/main/java/org/apache/shenyu/springboot/starter/sync/data/nacos/NacosSyncDataConfiguration.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-nacos/src/main/java/org/apache/shenyu/springboot/starter/sync/data/nacos/NacosSyncDataConfiguration.java
@@ -103,6 +103,9 @@ public class NacosSyncDataConfiguration {
if (nacosConfig.getPassword() != null) {
properties.put(PropertyKeyConst.PASSWORD,
nacosConfig.getPassword());
}
+ if (StringUtils.isNotBlank(nacosConfig.getContextPath())) {
+ properties.put(PropertyKeyConst.CONTEXT_PATH,
nacosConfig.getContextPath());
+ }
}
return NacosFactory.createConfigService(properties);
}
diff --git
a/shenyu-sync-data-center/shenyu-sync-data-nacos/src/main/java/org/apache/shenyu/sync/data/nacos/config/NacosConfig.java
b/shenyu-sync-data-center/shenyu-sync-data-nacos/src/main/java/org/apache/shenyu/sync/data/nacos/config/NacosConfig.java
index 44e7363c5f..bfceb42fdd 100644
---
a/shenyu-sync-data-center/shenyu-sync-data-nacos/src/main/java/org/apache/shenyu/sync/data/nacos/config/NacosConfig.java
+++
b/shenyu-sync-data-center/shenyu-sync-data-nacos/src/main/java/org/apache/shenyu/sync/data/nacos/config/NacosConfig.java
@@ -29,6 +29,8 @@ public class NacosConfig {
private String password;
+ private String contextPath;
+
private NacosACMConfig acm;
/**
@@ -103,6 +105,24 @@ public class NacosConfig {
this.password = password;
}
+ /**
+ * Gets the value of contextPath.
+ *
+ * @return the value of contextPath
+ */
+ public String getContextPath() {
+ return contextPath;
+ }
+
+ /**
+ * Sets the contextPath.
+ *
+ * @param contextPath contextPath
+ */
+ public void setContextPath(final String contextPath) {
+ this.contextPath = contextPath;
+ }
+
/**
* get acm.
*
@@ -134,12 +154,13 @@ public class NacosConfig {
&& Objects.equals(namespace, that.namespace)
&& Objects.equals(username, that.username)
&& Objects.equals(password, that.password)
+ && Objects.equals(contextPath, that.contextPath)
&& Objects.equals(acm, that.acm);
}
@Override
public int hashCode() {
- return Objects.hash(url, namespace, username, password, acm);
+ return Objects.hash(url, namespace, username, password, contextPath,
acm);
}
@Override
@@ -157,6 +178,9 @@ public class NacosConfig {
+ ", password='"
+ password
+ '\''
+ + ", contextPath='"
+ + contextPath
+ + '\''
+ ", acm="
+ acm
+ '}';
diff --git
a/shenyu-sync-data-center/shenyu-sync-data-nacos/src/test/java/org/apache/shenyu/sync/data/nacos/config/NacosConfigTest.java
b/shenyu-sync-data-center/shenyu-sync-data-nacos/src/test/java/org/apache/shenyu/sync/data/nacos/config/NacosConfigTest.java
index aaa7fa742d..9d32392366 100644
---
a/shenyu-sync-data-center/shenyu-sync-data-nacos/src/test/java/org/apache/shenyu/sync/data/nacos/config/NacosConfigTest.java
+++
b/shenyu-sync-data-center/shenyu-sync-data-nacos/src/test/java/org/apache/shenyu/sync/data/nacos/config/NacosConfigTest.java
@@ -38,6 +38,8 @@ public final class NacosConfigTest {
private static final String USERNAME = "username";
+ private static final String CONTEXT_PATH = "nacos";
+
private static final NacosACMConfig ACM = new NacosACMConfig();
private NacosConfig nacosConfig;
@@ -51,12 +53,14 @@ public final class NacosConfigTest {
nacosConfig.setNamespace(NAMESPACE);
nacosConfig.setPassword(PASSWORD);
nacosConfig.setUsername(USERNAME);
+ nacosConfig.setContextPath(CONTEXT_PATH);
nacosConfig.setAcm(ACM);
that = new NacosConfig();
that.setUrl(URL);
that.setNamespace(NAMESPACE);
that.setPassword(PASSWORD);
that.setUsername(USERNAME);
+ that.setContextPath(CONTEXT_PATH);
that.setAcm(ACM);
}
@@ -66,6 +70,7 @@ public final class NacosConfigTest {
assertEquals(NAMESPACE, nacosConfig.getNamespace());
assertEquals(PASSWORD, nacosConfig.getPassword());
assertEquals(USERNAME, nacosConfig.getUsername());
+ assertEquals(CONTEXT_PATH, nacosConfig.getContextPath());
assertEquals(ACM, nacosConfig.getAcm());
}
@@ -80,7 +85,7 @@ public final class NacosConfigTest {
@Test
public void testHashCode() {
assertEquals(Objects.hash(nacosConfig.getUrl(),
nacosConfig.getNamespace(),
- nacosConfig.getUsername(), nacosConfig.getPassword(),
nacosConfig.getAcm()),
+ nacosConfig.getUsername(), nacosConfig.getPassword(),
nacosConfig.getContextPath(), nacosConfig.getAcm()),
nacosConfig.hashCode());
}
}