{"record":{"id":"ddf6c7464d3c7e99","repo":"alibaba/spring-cloud-alibaba","slug":"configservice-is-not-initialized","errorCode":null,"errorMessage":"ConfigService is not initialized","messagePattern":"ConfigService is not initialized","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigManager.java","lineNumber":89,"sourceCode":"\t\t\t\t\t\tnacosConfigProperties.assembleConfigServiceProperties());\n\t\t\t}\n\t\t}\n\t\tcatch (NacosException e) {\n\t\t\tString serverAddr = nacosConfigProperties.getServerAddr();\n\t\t\tString message = e.getMessage();\n\t\t\tlog.error(message != null ? message : \"NacosException\");\n\t\t\tthrow new NacosConnectionFailureException(\n\t\t\t\t\tserverAddr != null ? serverAddr : \"\", message != null ? message : \"\", e);\n\t\t}\n\t\treturn service;\n\t}\n\n\tpublic ConfigService getConfigService() {\n\t\tif (Objects.isNull(service)) {\n\t\t\tcreateConfigService(this.nacosConfigProperties);\n\t\t}\n\t\tif (service == null) {\n\t\t\tthrow new IllegalStateException(\"ConfigService is not initialized\");\n\t\t}\n\t\treturn service;\n\t}\n\n\tpublic NacosConfigProperties getNacosConfigProperties() {\n\t\treturn nacosConfigProperties;\n\t}\n\n}\n","sourceCodeStart":71,"sourceCodeEnd":99,"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/NacosConfigManager.java#L71-L99","documentation":"Thrown by NacosConfigManager.getConfigService() when the static ConfigService singleton `service` is still null after a createConfigService(...) attempt. Normally createConfigService either sets the singleton via NacosFactory.createConfigService(...) or throws NacosConnectionFailureException, so this IllegalStateException is a defensive guard reached when the singleton was never initialized for this manager's lifecycle (e.g., a NacosConfigManager built directly without getInstance/createConfigService, or createConfigService returned without assigning because service was concurrently cleared/never assigned). It signals the Nacos config client was not constructed before first use.","triggerScenarios":"getConfigService() invoked on a NacosConfigManager whose createConfigService did not run or did not assign service; calling getConfigService during bootstrap before getInstance(...) registered the singleton; a code path that constructs `new NacosConfigManager(props)` and immediately calls getConfigService without prior initialization.","commonSituations":"Misordered bean initialization where the manager bean is used before its config-service wiring completes; a custom factory that bypasses NacosConfigManager.getInstance; an upgrade where the static-singleton contract changed; tests that instantiate the manager directly.","solutions":["Ensure NacosConfigManager is obtained through getInstance(NacosConfigProperties) so createConfigService runs and assigns the singleton.","Confirm spring.cloud.nacos.config.* properties are present so assembleConfigServiceProperties() yields a usable client config; a connection problem normally surfaces as NacosConnectionFailureException first — check logs just above this error.","Avoid constructing NacosConfigManager directly with the public constructor; let Spring auto-configuration create and initialize it.","If the error appears only in tests, bootstrap the NacosConfigProperties bean and call getInstance(properties) before asserting getConfigService()."],"exampleFix":"// before (manual construction misses initialization)\nNacosConfigManager mgr = new NacosConfigManager(properties);\nConfigService cs = mgr.getConfigService(); // -> IllegalStateException\n// after: go through getInstance to trigger createConfigService\nNacosConfigManager mgr = NacosConfigManager.getInstance(properties);\nConfigService cs = mgr.getConfigService();","handlingStrategy":"validation","validationCode":"// Obtain the manager via getInstance so createConfigService runs; assert non-null config service before use.\nNacosConfigManager mgr = NacosConfigManager.getInstance(nacosConfigProperties);\nObjects.requireNonNull(mgr, \"NacosConfigManager instance\");\nConfigService cs = mgr.getConfigService();","typeGuard":null,"tryCatchPattern":"try {\n    return nacosConfigManager.getConfigService();\n} catch (IllegalStateException e) {\n    // 'ConfigService is not initialized' -> ensure spring.cloud.nacos.config.* present and getInstance used\n    throw e;\n}","preventionTips":["Acquire NacosConfigManager through getInstance(properties), not the public constructor.","Keep spring.cloud.nacos.config.* properties populated.","Look for NacosConnectionFailureException just before this error as the real root cause."],"tags":["nacos","config","initialization","lifecycle","startup"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}