diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/nacos/NacosConfigModifier.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/nacos/NacosConfigModifier.java index 671a4fc37b..ff189195db 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/nacos/NacosConfigModifier.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/extend/nacos/NacosConfigModifier.java @@ -54,6 +54,14 @@ public class NacosConfigModifier implements PolarisConfigModifier { * nacos contextPath. */ public static final String CONTEXT_PATH = "contextPath"; + /** + * nacos namespace. + */ + public static final String NAMESPACE = "namespace"; + /** + * nacos group. + */ + public static final String GROUP = "group"; private static final Logger LOGGER = LoggerFactory.getLogger(NacosConfigModifier.class); private static final String ID = "nacos"; private final NacosContextProperties nacosContextProperties; @@ -114,6 +122,14 @@ public void modify(ConfigurationImpl configuration) { metadata.put(CONTEXT_PATH, nacosContextProperties.getContextPath()); } + if (StringUtils.isNotBlank(nacosContextProperties.getNamespace())) { + metadata.put(NAMESPACE, nacosContextProperties.getNamespace()); + } + + if (StringUtils.isNotBlank(nacosContextProperties.getGroup())) { + metadata.put(GROUP, nacosContextProperties.getGroup()); + } + configuration.getGlobal().getServerConnectors().add(serverConnectorConfig); DiscoveryConfigImpl discoveryConfig = new DiscoveryConfigImpl(); discoveryConfig.setServerConnectorId(ID); diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/extend/nacos/NacosContextPropertiesTest.java b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/extend/nacos/NacosContextPropertiesTest.java index acdf55d581..0d5d1a2b24 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/extend/nacos/NacosContextPropertiesTest.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/extend/nacos/NacosContextPropertiesTest.java @@ -84,6 +84,8 @@ public void testModify() { assertThat(metadata.get(NacosConfigModifier.USERNAME)).isEqualTo(nacosContextProperties.getUsername()); assertThat(metadata.get(NacosConfigModifier.PASSWORD)).isEqualTo(nacosContextProperties.getPassword()); assertThat(metadata.get(NacosConfigModifier.CONTEXT_PATH)).isEqualTo(nacosContextProperties.getContextPath()); + assertThat(metadata.get(NacosConfigModifier.NAMESPACE)).isEqualTo(nacosContextProperties.getNamespace()); + assertThat(metadata.get(NacosConfigModifier.GROUP)).isEqualTo(nacosContextProperties.getGroup()); } @SpringBootApplication