alibaba/spring-cloud-alibaba · critical · IllegalStateException

ConfigService is not initialized

Error message

ConfigService is not initialized

What it means

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.

Solutions

  1. Ensure NacosConfigManager is obtained through getInstance(NacosConfigProperties) so createConfigService runs and assigns the singleton.
  2. 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.
  3. Avoid constructing NacosConfigManager directly with the public constructor; let Spring auto-configuration create and initialize it.
  4. If the error appears only in tests, bootstrap the NacosConfigProperties bean and call getInstance(properties) before asserting getConfigService().

Example fix

// before (manual construction misses initialization)
NacosConfigManager mgr = new NacosConfigManager(properties);
ConfigService cs = mgr.getConfigService(); // -> IllegalStateException
// after: go through getInstance to trigger createConfigService
NacosConfigManager mgr = NacosConfigManager.getInstance(properties);
ConfigService cs = mgr.getConfigService();
Defensive patterns

Strategy: validation

Validate before calling

// Obtain the manager via getInstance so createConfigService runs; assert non-null config service before use.
NacosConfigManager mgr = NacosConfigManager.getInstance(nacosConfigProperties);
Objects.requireNonNull(mgr, "NacosConfigManager instance");
ConfigService cs = mgr.getConfigService();

Try / catch

try {
    return nacosConfigManager.getConfigService();
} catch (IllegalStateException e) {
    // 'ConfigService is not initialized' -> ensure spring.cloud.nacos.config.* present and getInstance used
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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

Appendix: source

Thrown at spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigManager.java:89

						nacosConfigProperties.assembleConfigServiceProperties());
			}
		}
		catch (NacosException e) {
			String serverAddr = nacosConfigProperties.getServerAddr();
			String message = e.getMessage();
			log.error(message != null ? message : "NacosException");
			throw new NacosConnectionFailureException(
					serverAddr != null ? serverAddr : "", message != null ? message : "", e);
		}
		return service;
	}

	public ConfigService getConfigService() {
		if (Objects.isNull(service)) {
			createConfigService(this.nacosConfigProperties);
		}
		if (service == null) {
			throw new IllegalStateException("ConfigService is not initialized");
		}
		return service;
	}

	public NacosConfigProperties getNacosConfigProperties() {
		return nacosConfigProperties;
	}

}

View on GitHub (pinned to 115d590110)