{"record":{"id":"f301a69ddb252fbe","repo":"spring-projects/spring-framework","slug":"no-matching-bean-found-for-qualifier-nei","errorCode":null,"errorMessage":"No matching {} bean found for qualifier '{}' - neither qualifier match nor bean name match!","messagePattern":"No matching (.+?) bean found for qualifier '(.+?)' - neither qualifier match nor bean name match!","errorType":"exception","errorClass":"NoSuchBeanDefinitionException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java","lineNumber":138,"sourceCode":"\t\tString[] candidateBeans = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, beanType);\n\t\tString matchingBean = null;\n\t\tfor (String beanName : candidateBeans) {\n\t\t\tif (isQualifierMatch(qualifier::equals, beanName, beanFactory)) {\n\t\t\t\tif (matchingBean != null) {\n\t\t\t\t\tthrow new NoUniqueBeanDefinitionException(beanType, matchingBean, beanName);\n\t\t\t\t}\n\t\t\t\tmatchingBean = beanName;\n\t\t\t}\n\t\t}\n\t\tif (matchingBean != null) {\n\t\t\treturn beanFactory.getBean(matchingBean, beanType);\n\t\t}\n\t\telse if (beanFactory.containsBean(qualifier) && beanFactory.isTypeMatch(qualifier, beanType)) {\n\t\t\t// Fallback: target bean at least found by bean name - probably a manually registered singleton.\n\t\t\treturn beanFactory.getBean(qualifier, beanType);\n\t\t}\n\t\telse {\n\t\t\tthrow new NoSuchBeanDefinitionException(qualifier, \"No matching \" + beanType.getSimpleName() +\n\t\t\t\t\t\" bean found for qualifier '\" + qualifier + \"' - neither qualifier match nor bean name match!\");\n\t\t}\n\t}\n\n\t/**\n\t * Determine the {@link Qualifier#value() qualifier value} for the given\n\t * annotated element.\n\t * @param annotatedElement the class, method or parameter to introspect\n\t * @return the associated qualifier value, or {@code null} if none\n\t * @since 6.2\n\t */\n\tpublic static @Nullable String getQualifierValue(AnnotatedElement annotatedElement) {\n\t\tQualifier qualifier = AnnotationUtils.getAnnotation(annotatedElement, Qualifier.class);\n\t\treturn (qualifier != null ? qualifier.value() : null);\n\t}\n\n\t/**\n\t * Check whether the named bean declares a qualifier of the given name.","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java#L120-L156","documentation":"Thrown by qualifiedBeanOfType(ListableBeanFactory, Class, String) when no bean of the requested type has a matching qualifier AND no bean with the qualifier string as its bean name exists. This is the 'not found at all' outcome of qualifier resolution — neither the annotation-based qualifier match nor the bean-name fallback succeeded.","triggerScenarios":"The qualifier string passed to qualifiedBeanOfType does not match any @Qualifier value on any bean of the type, and there is no bean with that string as its name. Lines 130-140 exhaust both the qualifier-match loop and the containsBean fallback before throwing.","commonSituations":"Typo in the qualifier string. The @Qualifier annotation was not placed on the bean definition (only on the injection point). Using a qualifier value that was intended but never declared on the target bean. Bean registered under a different name than expected.","solutions":["Verify the qualifier string exactly matches a @Qualifier value declared on one of the candidate bean definitions.","Ensure the target bean class has @Qualifier(\"expectedValue\") on its class or @Bean method.","If relying on bean-name matching, confirm a bean with that exact name is registered."],"exampleFix":"// before\n// Injection point\n@Autowired\n@Qualifier(\"primary\")\nprivate DataSource ds;\n\n// Bean — no @Qualifier declared\n@Bean\nDataSource myDataSource() { ... }\n\n// after\n@Bean\n@Qualifier(\"primary\")\nDataSource myDataSource() { ... }","handlingStrategy":"validation","validationCode":"// Verify a bean with the qualifier exists before resolving\nListableBeanFactory lbf = (ListableBeanFactory) beanFactory;\nboolean found = false;\nfor (String name : lbf.getBeanNamesForType(beanType)) {\n    // check for @Qualifier annotation or bean name match\n    if (qualifier.equals(name) || hasQualifierAnnotation(name, qualifier, lbf)) {\n        found = true; break;\n    }\n}\nif (!found) {\n    throw new IllegalStateException(\"No bean with qualifier '\" + qualifier + \"' of type \" + beanType);\n}","typeGuard":null,"tryCatchPattern":"try {\n    return BeanFactoryAnnotationUtils.qualifiedBeanOfType(lbf, beanType, qualifier);\n} catch (NoSuchBeanDefinitionException ex) {\n    // neither qualifier match nor bean name match\n    // register the bean or fix the qualifier string\n    throw new IllegalArgumentException(\"Invalid qualifier: \" + qualifier, ex);\n}","preventionTips":["Ensure @Qualifier is placed on the bean definition (class or @Bean method), not just on the injection point.","Double-check qualifier strings for typos — they must match exactly.","If relying on bean-name fallback, confirm the bean is registered under that exact name."],"tags":["spring","qualifier","missing-bean","di"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}