{"record":{"id":"e5050402ebc5b0ef","repo":"spring-projects/spring-framework","slug":"no-qualifying-bean-of-type-available-e50504","errorCode":null,"errorMessage":"No qualifying bean of type '{}' available","messagePattern":"No qualifying bean of type '(.+?)' available","errorType":"exception","errorClass":"NoSuchBeanDefinitionException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java","lineNumber":89,"sourceCode":"public interface ObjectProvider<T> extends ObjectFactory<T>, Iterable<T> {\n\n\t/**\n\t * A predicate for unfiltered type matches, including non-default candidates\n\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 */","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java#L71-L107","documentation":"NoSuchBeanDefinitionException thrown by the default ObjectProvider.getObject() at line 89 when the provider's iterator is empty — i.e. no bean of the generic type exists. ObjectProvider.getObject() is strict: it demands exactly one bean, so an empty stream fails here (whereas getIfAvailable() would return null).","triggerScenarios":"Calling objectProvider.getObject() (directly or via getIfAvailable fallback path that rethrows) when no candidate of type T is registered. Common with ObjectProvider<T> injected as a lazy lookup handle.","commonSituations":"An optional feature bean that is conditionally absent; cross-module injection where the providing module is not on the classpath/config; calling getObject() instead of the null-safe getIfAvailable().","solutions":["Use getIfAvailable() / getIfAvailable(() -> default) / ifAvailable(consumer) for optional beans.","Register the missing bean if it is mandatory.","Use getObject() only when the bean is contractually guaranteed to exist."],"exampleFix":"// before\nOptionalFeature f = optionalFeatureProvider.getObject(); // throws if absent\n\n// after\nOptionalFeature f = optionalFeatureProvider.getIfAvailable(() -> defaultFeature);","handlingStrategy":"fallback","validationCode":"// Prefer the null-safe accessor\nif (provider.getIfAvailable() == null) {\n    // bean genuinely absent; handle gracefully\n}","typeGuard":"static <T> boolean isPresent(ObjectProvider<T> p) {\n    return p.getIfAvailable() != null;\n}","tryCatchPattern":null,"preventionTips":["Use getIfAvailable()/ifAvailable() for optional beans instead of getObject().","Reserve getObject() for beans contractually guaranteed to exist.","Add a default supplier for graceful fallback."],"tags":["dependency-injection","object-provider","no-such-bean"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}