[ISSUE #12219] 修复nacos-client中config的ServerListManager解析endpoint失败问题 (#12220)

* [ISSUE #12219] 修复nacos-client中config的ServerListManager解析endpoint失败问题

* [ISSUE #12219] 修复nacos-client中config的ServerListManager解析endpoint失败问题
This commit is contained in:
misakacoder 2024-07-01 13:53:59 +08:00 committed by GitHub
parent 92a3d17681
commit 97162438f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -318,7 +318,7 @@ public class ServerListManager implements Closeable {
if (StringUtils.isNotBlank(endpointUrl)) {
this.serverAddrsStr = "";
}
this.endpoint = endpointUrl;
endpointTmp = endpointUrl;
}
this.endpoint = StringUtils.isNotBlank(endpointTmp) ? endpointTmp : "";
}

View File

@ -280,4 +280,17 @@ class ServerListManagerTest {
assertFalse(serverListManager.getName().contains("endpointContextPath"));
assertTrue(serverListManager.getName().contains("contextPath"));
}
@Test
void testUseEndpointParsingRule() throws NacosException {
System.setProperty("nacos.endpoint", "127.0.0.1");
Properties properties = new Properties();
properties.setProperty(PropertyKeyConst.ENDPOINT, "${nacos.endpoint}");
properties.setProperty(PropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE, "true");
properties.setProperty(PropertyKeyConst.ENDPOINT_PORT, "9090");
final NacosClientProperties clientProperties = NacosClientProperties.PROTOTYPE.derive(properties);
ServerListManager serverListManager = new ServerListManager(clientProperties);
String addressServerUrl = serverListManager.addressServerUrl;
assertTrue(addressServerUrl.startsWith("http://127.0.0.1"));
}
}