alibaba/spring-cloud-alibaba · error · IllegalArgumentException
illegal URI: {uris}
Error message
illegal URI: {uris} What it means
Thrown by NacosConfigDataLocationResolver.getUri when new URI(uris) raises URISyntaxException. The method first prepends 'http://' when the string lacks a scheme, then parses; if the resulting string is still not a valid URI (illegal characters, malformed host, bad percent-encoding, stray spaces), parsing fails and IllegalArgumentException("illegal URI: <value>") is thrown.
Source
Thrown at spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/configdata/NacosConfigDataLocationResolver.java:240
ConfigDataLocationResolverContext resolverContext) {
List<?> springConfigImportProperties = resolverContext.getBinder()
.bind(SPRING_CONFIG_IMPORT_PROPERTIES, List.class).get();
if (!springConfigImportProperties.isEmpty() && !bootstrapContext.isRegistered(NacosConfigManager.class)) {
bootstrapContext.register(NacosConfigManager.class,
BootstrapRegistry.InstanceSupplier.of(NacosConfigManager.getInstance(properties)));
}
}
private URI getUri(String uris) {
if (!uris.startsWith("http://") && !uris.startsWith("https://")) {
uris = "http://" + uris;
}
URI uri;
try {
uri = new URI(uris);
}
catch (URISyntaxException e) {
throw new IllegalArgumentException("illegal URI: " + uris);
}
return uri;
}
private @Nullable String groupFor(URI uri, NacosConfigProperties properties) {
Map<String, String> queryMap = getQueryMap(uri);
return queryMap.containsKey(GROUP) ? queryMap.get(GROUP) : properties.getGroup();
}
private Map<String, String> getQueryMap(URI uri) {
String query = uri.getQuery();
if (StringUtils.isBlank(query)) {
return Collections.emptyMap();
}
Map<String, String> result = new HashMap<>(4);
for (String entry : query.split("&")) {
String[] kv = entry.split("=");
if (kv.length == 2) {View on GitHub (pinned to 115d590110)
Solutions
- Correct the import string: ensure host:port and dataId are well-formed and percent-encode spaces/special chars.
- Keep server-addr in spring.cloud.nacos.config.server-addr and the import minimal: `nacos:app.yml`.
- If a cluster address list is needed, use the standard form and avoid illegal characters in the URI.
- Validate the string with new URI(...) locally to find the offending character.
Example fix
# before (space / illegal char) spring.config.import: "nacos://my host:8848/app.yml" # after spring.cloud.nacos.config.server-addr: my-host:8848 spring.config.import: "nacos:app.yml"
Defensive patterns
Strategy: validation
Validate before calling
// Validate the import string parses as a URI before relying on config-data import.
String raw = importValue;
if (!raw.startsWith("http://") && !raw.startsWith("https://")) raw = "http://" + raw;
try { new URI(raw); } catch (URISyntaxException e) { /* reject, show offending chars */ } Type guard
static boolean isParsableNacosUri(String uris) {
if (uris == null) return false;
String s = (!uris.startsWith("http://") && !uris.startsWith("https://")) ? "http://" + uris : uris;
try { new URI(s); return true; } catch (URISyntaxException e) { return false; }
} Prevention
- Keep server-addr in spring.cloud.nacos.config.server-addr and the import minimal.
- Percent-encode spaces and special characters.
- Avoid cluster address lists with illegal URI characters.
When it happens
Trigger: A spring.config.import nacos: value that, after http:// prepending, is not parseable as a URI — e.g., unencoded spaces, an invalid port, mismatched brackets, a malformed host, or illegal characters in the dataId/query.
Common situations: Paste errors with spaces in the import string; non-URL-encoded special characters; a missing/extra colon; a server-addr with brackets or commas copied from a cluster config without encoding.
Related errors
- dataId must be specified
- illegal dataId
- NacosConfigManager not available
- NacosConfigProperties not available
- Binder not available in BootstrapContext
AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14).
Data as JSON: /api/errors/4b9b849aed34aa14.
Report an issue: GitHub.