apache/dubbo · error · IllegalStateException

Found more than one config by name: <name>, instances: <list

Error message

Found more than one config by name: <name>, instances: <list>. Please remove redundant configs or get config by id.

What it means

Thrown by AbstractConfigManager.getConfigByName() when a name lookup (via the 'name' property, read through CONFIG_NAME_READ_METHOD) returns more than one config of the same type. Unlike id-based lookup, name-based lookup is ambiguous when two configs share a name, so Dubbo refuses to pick one arbitrarily.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java:359

    /**
     * Get config by name if existed
     *
     * @param cls
     * @param name
     * @return
     */
    protected <C extends AbstractConfig> C getConfigByName(Class<? extends C> cls, String name) {
        Map<String, ? extends C> configsMap = getConfigsMap(cls);
        if (configsMap.isEmpty()) {
            return null;
        }
        // try to find config by name
        if (ReflectUtils.hasMethod(cls, CONFIG_NAME_READ_METHOD)) {
            List<C> list = configsMap.values().stream()
                    .filter(cfg -> name.equals(getConfigName(cfg)))
                    .collect(Collectors.toList());
            if (list.size() > 1) {
                throw new IllegalStateException("Found more than one config by name: " + name + ", instances: " + list
                        + ". Please remove redundant configs or get config by id.");
            } else if (list.size() == 1) {
                return list.get(0);
            }
        }
        return null;
    }

    private <C extends AbstractConfig> String getConfigName(C config) {
        try {
            return ReflectUtils.getProperty(config, CONFIG_NAME_READ_METHOD);
        } catch (Exception e) {
            return null;
        }
    }

    protected <C extends AbstractConfig> Optional<C> findConfigByValue(Collection<C> values, C config) {
        // 1. find same config instance (speed up raw api usage)

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Give each config a unique 'name' (or rely on unique ids).
  2. Look up the config by id instead of name when ambiguity is possible.
  3. Merge the duplicate configs into one.

Example fix

<!-- before -->
<dubbo:registry name="main" address="zk1"/>
<dubbo:registry name="main" address="zk2"/>
<!-- after -->
<dubbo:registry id="r1" name="main1" address="zk1"/>
<dubbo:registry id="r2" name="main2" address="zk2"/>
Defensive patterns

Strategy: validation

Validate before calling

// Before name lookup, ensure the name is unique across the type
String name = "main";
List<? extends RegistryConfig> matches = configManager.getConfigs(RegistryConfig.class).stream()
    .filter(c -> name.equals(c.getName()))
    .collect(Collectors.toList());
if (matches.size() > 1) {
    throw new IllegalStateException("Ambiguous name '" + name + "' across " + matches);
}
configManager.getConfigByName(RegistryConfig.class, name);

Type guard

static <C extends AbstractConfig> boolean isNameUnique(ConfigManager cm, Class<C> cls, String name) {
    long n = cm.getConfigs(cls).stream().filter(c -> name.equals(c.getName())).count();
    return n <= 1;
}

Try / catch

try {
    cfg = configManager.getConfigByName(RegistryConfig.class, name);
} catch (IllegalStateException e) {
    if (e.getMessage().contains("Found more than one config by name")) {
        cfg = configManager.getConfig(RegistryConfig.class, id).orElse(null); // fall back to id
    } else throw e;
}

Prevention

When it happens

Trigger: Two configs of the same type (e.g. two RegistryConfig) both having name="myRegistry", then looking up by that name. Setting the same 'name' on multiple bean definitions.

Common situations: Reusing a friendly name across multiple registry/protocol configs. Spring bean definitions where name (not id) collides. Copy-pasting config blocks and forgetting to rename.

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/14c68c93ee86ccc5. Report an issue: GitHub.