{"record":{"id":"28447a3b28702612","repo":"apache/dubbo","slug":"expected-single-instance-of-configtype-but-foun","errorCode":null,"errorMessage":"Expected single instance of <configType>, but found <size> instances, please remove redundant configs. instances: <configsMap.values()>","messagePattern":"Expected single instance of <configType>, but found <size> instances, please remove redundant configs\\. instances: <configsMap\\.values\\(\\)>","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java","lineNumber":272,"sourceCode":"        if (uniqueConfigTypes.contains(config.getClass())) {\n            return true;\n        }\n        for (Class<? extends AbstractConfig> uniqueConfigType : uniqueConfigTypes) {\n            if (uniqueConfigType.isAssignableFrom(config.getClass())) {\n                return true;\n            }\n        }\n        return false;\n    }\n\n    protected <C extends AbstractConfig> C getSingleConfig(String configType) throws IllegalStateException {\n        Map<String, AbstractConfig> configsMap = getConfigsMap(configType);\n        int size = configsMap.size();\n        if (size < 1) {\n            //                throw new IllegalStateException(\"No such \" + configType.getName() + \" is found\");\n            return null;\n        } else if (size > 1) {\n            throw new IllegalStateException(\"Expected single instance of \" + configType + \", but found \" + size\n                    + \" instances, please remove redundant configs. instances: \" + configsMap.values());\n        }\n        return (C) configsMap.values().iterator().next();\n    }\n\n    protected <C extends AbstractConfig> Optional<C> findDuplicatedConfig(Map<String, C> configsMap, C config) {\n\n        // find by value\n        Optional<C> prevConfig = findConfigByValue(configsMap.values(), config);\n        if (prevConfig.isPresent()) {\n            if (prevConfig.get() == config) {\n                // the new one is same as existing one\n                return prevConfig;\n            }\n\n            // ignore duplicated equivalent config\n            if (logger.isInfoEnabled() && duplicatedConfigs.add(config)) {\n                logger.info(\"Ignore duplicated config: \" + config);","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java#L254-L290","documentation":"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.","triggerScenarios":"Registering two ApplicationConfig (or other unique-type) beans, or loading two via properties with different ids. Calling getSingleConfig(\"application\") when two application configs exist.","commonSituations":"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.","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)."],"exampleFix":"<!-- before: two application configs -->\n<dubbo:application name=\"a\"/>\n<dubbo:application name=\"b\"/>\n<!-- after: one -->\n<dubbo:application name=\"a\"/>","handlingStrategy":"validation","validationCode":"Map<String, AbstractConfig> map = configManager.getConfigsMap(\"application\");\nif (map != null && map.size() > 1) {\n    throw new IllegalStateException(\"Multiple application configs detected: \" + map.values());\n}\nconfigManager.getSingleConfig(\"application\");","typeGuard":"static boolean isUniqueConfigPresent(ConfigManager cm, String type) {\n    Map<String, AbstractConfig> m = cm.getConfigsMap(type);\n    return m == null || m.size() <= 1;\n}","tryCatchPattern":"try {\n    ApplicationConfig app = (ApplicationConfig) configManager.getSingleConfig(\"application\");\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Expected single instance\")) {\n        // deduplicate configs or switch to OVERRIDE mode\n    } else throw e;\n}","preventionTips":["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."],"tags":["config","duplicate","unique-config","startup"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}