{"record":{"id":"16a51a54d2356bb5","repo":"spring-projects/spring-framework","slug":"no-qualifying-bean-of-type-available-more-th","errorCode":null,"errorMessage":"No qualifying bean of type '{}' available: more than 1 matching bean","messagePattern":"No qualifying bean of type '(.+?)' available: more than 1 matching bean","errorType":"exception","errorClass":"NoUniqueBeanDefinitionException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java","lineNumber":93,"sourceCode":"\t * but still excluding non-autowire candidates when used on injection points.\n\t * @since 6.2.3\n\t * @see #stream(Predicate)\n\t * @see #orderedStream(Predicate)\n\t * @see org.springframework.beans.factory.config.BeanDefinition#isAutowireCandidate()\n\t * @see org.springframework.beans.factory.support.AbstractBeanDefinition#isDefaultCandidate()\n\t */\n\tPredicate<Class<?>> UNFILTERED = (clazz -> true);\n\n\n\t@Override\n\tdefault T getObject() throws BeansException {\n\t\tIterator<T> it = iterator();\n\t\tif (!it.hasNext()) {\n\t\t\tthrow new NoSuchBeanDefinitionException(Object.class);\n\t\t}\n\t\tT result = it.next();\n\t\tif (it.hasNext()) {\n\t\t\tthrow new NoUniqueBeanDefinitionException(Object.class, 2, \"more than 1 matching bean\");\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Return an instance (possibly shared or independent) of the object\n\t * managed by this factory.\n\t * <p>Allows for specifying explicit construction arguments, along the\n\t * lines of {@link BeanFactory#getBean(String, Object...)}.\n\t * @param args arguments to use when creating a corresponding instance\n\t * @return an instance of the bean\n\t * @throws BeansException in case of creation errors\n\t * @see #getObject()\n\t */\n\tdefault T getObject(@Nullable Object... args) throws BeansException {\n\t\tthrow new UnsupportedOperationException(\"Retrieval with arguments not supported -\" +\n\t\t\t\t\"for custom ObjectProvider classes, implement getObject(Object...) for your purposes\");\n\t}","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java#L75-L111","documentation":"NoUniqueBeanDefinitionException thrown by the default ObjectProvider.getObject() at line 93 when the iterator yields more than one bean. getObject() demands uniqueness; multiple candidates without a primary/qualifier resolution fail here. Use getIfUnique() for null-safe multi-candidate handling.","triggerScenarios":"objectProvider.getObject() where two or more beans of T are registered and none is resolved as primary; calling getObject() in code that assumed a single source.","commonSituations":"Two implementations of an interface; an interface plus a Mockito test double both active in a slice test; multiple DataSource beans.","solutions":["Use getIfUnique() / getIfUnique(() -> default) / ifUnique(consumer) for multi-candidate providers.","Mark one candidate @Primary or narrow with @Qualifier so a unique bean exists.","Inject List<T> / Stream<T> via the provider when all candidates are wanted."],"exampleFix":"// before\nT bean = provider.getObject(); // throws if 2 candidates\n\n// after\nT bean = provider.getIfUnique(() -> fallback);","handlingStrategy":"fallback","validationCode":"// Use the unique-safe accessor for possibly-ambiguous providers\nT bean = provider.getIfUnique();\nif (bean == null) { /* 0 or many; disambiguate */ }","typeGuard":"static <T> boolean isUnique(ObjectProvider<T> p) {\n    return p.stream().count() == 1;\n}","tryCatchPattern":null,"preventionTips":["Use getIfUnique()/ifUnique() when multiple candidates may exist.","Designate a @Primary candidate so getObject() can succeed.","Inject List<T>/Stream<T> when you want all candidates."],"tags":["dependency-injection","object-provider","no-unique-bean"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}