apache/dubbo · error · IllegalStateException
Expected single instance of <configType>, but found <size> i
Error message
Expected single instance of <configType>, but found <size> instances, please remove redundant configs. instances: <configsMap.values()>
What it means
Thrown by AbstractConfigManager.getSingleConfig() when more than one config instance exists for a given config type tag. getSingleConfig() is used for config types that are expected to be unique (like ApplicationConfig, MonitorConfig); finding multiple violates that uniqueness expectation. This is a startup-time integrity check surfaced after configs are loaded.
Source
Thrown at dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java:272
if (uniqueConfigTypes.contains(config.getClass())) {
return true;
}
for (Class<? extends AbstractConfig> uniqueConfigType : uniqueConfigTypes) {
if (uniqueConfigType.isAssignableFrom(config.getClass())) {
return true;
}
}
return false;
}
protected <C extends AbstractConfig> C getSingleConfig(String configType) throws IllegalStateException {
Map<String, AbstractConfig> configsMap = getConfigsMap(configType);
int size = configsMap.size();
if (size < 1) {
// throw new IllegalStateException("No such " + configType.getName() + " is found");
return null;
} else if (size > 1) {
throw new IllegalStateException("Expected single instance of " + configType + ", but found " + size
+ " instances, please remove redundant configs. instances: " + configsMap.values());
}
return (C) configsMap.values().iterator().next();
}
protected <C extends AbstractConfig> Optional<C> findDuplicatedConfig(Map<String, C> configsMap, C config) {
// find by value
Optional<C> prevConfig = findConfigByValue(configsMap.values(), config);
if (prevConfig.isPresent()) {
if (prevConfig.get() == config) {
// the new one is same as existing one
return prevConfig;
}
// ignore duplicated equivalent config
if (logger.isInfoEnabled() && duplicatedConfigs.add(config)) {
logger.info("Ignore duplicated config: " + config);View on GitHub (pinned to 3a3043227f)
Solutions
- Remove the duplicate config so only one instance of the unique type remains.
- If multiple contexts are loaded, ensure the unique config is defined in only one (the parent).
- Switch config mode to OVERRIDE or IGNORE to resolve duplicates non-fatally (see ConfigMode).
Example fix
<!-- before: two application configs --> <dubbo:application name="a"/> <dubbo:application name="b"/> <!-- after: one --> <dubbo:application name="a"/>
Defensive patterns
Strategy: validation
Validate before calling
Map<String, AbstractConfig> map = configManager.getConfigsMap("application");
if (map != null && map.size() > 1) {
throw new IllegalStateException("Multiple application configs detected: " + map.values());
}
configManager.getSingleConfig("application"); Type guard
static boolean isUniqueConfigPresent(ConfigManager cm, String type) {
Map<String, AbstractConfig> m = cm.getConfigsMap(type);
return m == null || m.size() <= 1;
} Try / catch
try {
ApplicationConfig app = (ApplicationConfig) configManager.getSingleConfig("application");
} catch (IllegalStateException e) {
if (e.getMessage().contains("Expected single instance")) {
// deduplicate configs or switch to OVERRIDE mode
} else throw e;
} Prevention
- Define unique-type configs (application, monitor) in exactly one Spring context.
- In multi-context apps, declare them only in the parent context.
- Use config-mode OVERRIDE/IGNORE if duplicates are unavoidable.
When it happens
Trigger: Registering two ApplicationConfig (or other unique-type) beans, or loading two via properties with different ids. Calling getSingleConfig("application") when two application configs exist.
Common situations: XML config defining <dubbo:application> twice (e.g. in a parent and child Spring context both loaded). Spring Boot auto-config plus an explicit bean producing two ApplicationConfig instances. Properties defining dubbo.application twice.
Related errors
- Duplicate Configs found for <configName>, only one unique <c
- More than 1 default extension name on extension {}: {}
- url missing protocol: "<url>"
- <config>.<key> == null
- Append parameters failed: <message>
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/28447a3b28702612.
Report an issue: GitHub.