alibaba/spring-cloud-alibaba · error · IllegalArgumentException

illegal dataId

Error message

illegal dataId

What it means

Thrown by NacosConfigDataLocationResolver.dataIdFor when the URI path, after stripping the leading '/', splits into more than one segment (parts.length != 1). A valid nacos import path must be a single segment (the dataId, e.g., '/app.yml'); a path like '/a/b' or '/dir/app.yml' has multiple segments and is rejected because dataId cannot encode a multi-segment path.

Source

Thrown at spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/configdata/NacosConfigDataLocationResolver.java:288

		return properties.getFileExtension();
	}

	private boolean refreshEnabledFor(URI uri, NacosConfigProperties properties) {
		Map<String, String> queryMap = getQueryMap(uri);
		return queryMap.containsKey(REFRESH_ENABLED)
				? Boolean.parseBoolean(queryMap.get(REFRESH_ENABLED))
				: properties.isRefreshEnabled();
	}

	private @Nullable String dataIdFor(URI uri) {
		String path = uri.getPath();
		// notice '/'
		if (path == null || path.length() <= 1) {
			return StringUtils.EMPTY;
		}
		String[] parts = path.substring(1).split("/");
		if (parts.length != 1) {
			throw new IllegalArgumentException("illegal dataId");
		}
		return parts[0];
	}

}

View on GitHub (pinned to 115d590110)

Solutions

  1. Use a flat dataId (Nacos dataIds are not hierarchical): `nacos:app.yml` or `nacos://host/app.yml`.
  2. If you need disambiguation, use distinct dataId names or the group query param instead of path segments.
  3. Remove any '/' inside the dataId portion of the import.

Example fix

# before
spring.config.import: "nacos:orders/app.yml"
# after
spring.config.import: "nacos:orders-app.yml?group=ORDER_GROUP"
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the dataId path is a single segment (no nested slashes).
String path = uri.getPath();
if (path == null || path.length() <= 1 || path.substring(1).split("/").length != 1) {
    // reject: dataId must be flat
}

Type guard

static boolean isFlatDataIdPath(String path) {
    if (path == null || path.length() <= 1) return false;
    return path.substring(1).split("/").length == 1;
}

Prevention

When it happens

Trigger: A nacos: import whose path contains slashes beyond the leading one — e.g., `nacos:dir/app.yml`, `nacos://host/a/b`, or `nacos:folder/sub/app.yml`. dataIdFor splits and sees >1 segment.

Common situations: Treating the Nacos dataId like a filesystem path with directories; grouping configs into nested-looking import strings; copying a path from elsewhere.

Related errors


AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14). Data as JSON: /api/errors/8ab75054ef4a0d12. Report an issue: GitHub.