alibaba/spring-cloud-alibaba · error · IllegalArgumentException

dataId must be specified

Error message

dataId must be specified

What it means

Thrown by NacosConfigDataLocationResolver.loadConfigDataResources after dataIdFor(uri) returns null or empty. dataIdFor derives the dataId from the URI's path; an empty path yields no dataId. In practice this means the spring.config.import nacos: location string has no path segment, so the resolver cannot know which config dataId to fetch.

Source

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

				.getBootstrapContext();

		bootstrapContext.registerIfAbsent(NacosConfigProperties.class,
				BootstrapRegistry.InstanceSupplier.of(properties));

		registerConfigManager(properties, bootstrapContext, resolverContext);

		return loadConfigDataResources(location, profiles, properties);
	}

	private List<NacosConfigDataResource> loadConfigDataResources(
			ConfigDataLocation location, Profiles profiles,
			NacosConfigProperties properties) {
		List<NacosConfigDataResource> result = new ArrayList<>();
		URI uri = getUri(location, properties);

		String dataIdNullable = dataIdFor(uri);
		if (dataIdNullable == null || dataIdNullable.isEmpty()) {
			throw new IllegalArgumentException("dataId must be specified");
		}
		String dataId = dataIdNullable;

		String group = groupFor(uri, properties);
		if (group == null) {
			group = "";
		}

		String suffix = suffixFor(uri, properties);
		if (suffix == null) {
			suffix = "";
		}

		String preference = preferenceFor(uri);
		if (preference == null) {
			preference = "";
		}

View on GitHub (pinned to 115d590110)

Solutions

  1. Add the dataId as the path of the import: `spring.config.import=nacos:app.yml` (optionally with group/suffix as query params).
  2. Use the full form `nacos://server-addr/dataId?group=...` when you need to set server-addr in the URI.
  3. Double-check that the import string is not truncated to just the scheme/host.

Example fix

# before
spring.config.import: "nacos:"
# after
spring.config.import: "nacos:app.yml"
# or with host
spring.config.import: "nacos://127.0.0.1:8848/app.yml?group=DEFAULT_GROUP"
Defensive patterns

Strategy: validation

Validate before calling

// Validate that every nacos: import contains a dataId path.
String imp = environment.getProperty("spring.config.import");
if (imp != null && imp.contains("nacos:")) {
    URI u = URI.create(imp.substring(imp.indexOf("nacos:")).replaceFirst("nacos:", "http://x/"));
    assert u.getPath() != null && u.getPath().length() > 1 : "dataId required in nacos: import";
}

Type guard

static boolean nacosImportHasDataId(String importValue) {
    if (importValue == null) return true;
    for (String part : importValue.split(",")) {
        String t = part.trim();
        if (t.startsWith("nacos:")) {
            String body = t.replaceFirst("^(optional:)?nacos:?", "");
            if (body.isEmpty() || (!body.contains("/") && !body.contains("."))) return false;
        }
    }
    return true;
}

Prevention

When it happens

Trigger: A nacos: import with no dataId in the path, e.g., `spring.config.import=nacos:` or `nacos://host:8848` with nothing after the host. The resolver computes uri.getPath() as empty/null and rejects it.

Common situations: Writing `spring.config.import=optional:nacos:` without a dataId; specifying only server-addr in the import and forgetting the dataId path; copying an incomplete example.

Related errors


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