{"record":{"id":"7b21a1ceba3a4a44","repo":"alibaba/spring-cloud-alibaba","slug":"dataid-must-be-specified","errorCode":null,"errorMessage":"dataId must be specified","messagePattern":"dataId must be specified","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/configdata/NacosConfigDataLocationResolver.java","lineNumber":174,"sourceCode":"\t\t\t\t.getBootstrapContext();\n\n\t\tbootstrapContext.registerIfAbsent(NacosConfigProperties.class,\n\t\t\t\tBootstrapRegistry.InstanceSupplier.of(properties));\n\n\t\tregisterConfigManager(properties, bootstrapContext, resolverContext);\n\n\t\treturn loadConfigDataResources(location, profiles, properties);\n\t}\n\n\tprivate List<NacosConfigDataResource> loadConfigDataResources(\n\t\t\tConfigDataLocation location, Profiles profiles,\n\t\t\tNacosConfigProperties properties) {\n\t\tList<NacosConfigDataResource> result = new ArrayList<>();\n\t\tURI uri = getUri(location, properties);\n\n\t\tString dataIdNullable = dataIdFor(uri);\n\t\tif (dataIdNullable == null || dataIdNullable.isEmpty()) {\n\t\t\tthrow new IllegalArgumentException(\"dataId must be specified\");\n\t\t}\n\t\tString dataId = dataIdNullable;\n\n\t\tString group = groupFor(uri, properties);\n\t\tif (group == null) {\n\t\t\tgroup = \"\";\n\t\t}\n\n\t\tString suffix = suffixFor(uri, properties);\n\t\tif (suffix == null) {\n\t\t\tsuffix = \"\";\n\t\t}\n\n\t\tString preference = preferenceFor(uri);\n\t\tif (preference == null) {\n\t\t\tpreference = \"\";\n\t\t}\n","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/configdata/NacosConfigDataLocationResolver.java#L156-L192","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add the dataId as the path of the import: `spring.config.import=nacos:app.yml` (optionally with group/suffix as query params).","Use the full form `nacos://server-addr/dataId?group=...` when you need to set server-addr in the URI.","Double-check that the import string is not truncated to just the scheme/host."],"exampleFix":"# before\nspring.config.import: \"nacos:\"\n# after\nspring.config.import: \"nacos:app.yml\"\n# or with host\nspring.config.import: \"nacos://127.0.0.1:8848/app.yml?group=DEFAULT_GROUP\"","handlingStrategy":"validation","validationCode":"// Validate that every nacos: import contains a dataId path.\nString imp = environment.getProperty(\"spring.config.import\");\nif (imp != null && imp.contains(\"nacos:\")) {\n    URI u = URI.create(imp.substring(imp.indexOf(\"nacos:\")).replaceFirst(\"nacos:\", \"http://x/\"));\n    assert u.getPath() != null && u.getPath().length() > 1 : \"dataId required in nacos: import\";\n}","typeGuard":"static boolean nacosImportHasDataId(String importValue) {\n    if (importValue == null) return true;\n    for (String part : importValue.split(\",\")) {\n        String t = part.trim();\n        if (t.startsWith(\"nacos:\")) {\n            String body = t.replaceFirst(\"^(optional:)?nacos:?\", \"\");\n            if (body.isEmpty() || (!body.contains(\"/\") && !body.contains(\".\"))) return false;\n        }\n    }\n    return true;\n}","tryCatchPattern":null,"preventionTips":["Always include a dataId path: nacos:app.yml.","Use the full nacos://host:port/dataId form when setting host in the URI.","Lint spring.config.import entries at startup."],"tags":["nacos","config-data","spring-boot","config-import","misconfiguration"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}