{"record":{"id":"a836c460d5efd88a","repo":"spring-projects/spring-framework","slug":"unsatisfied-dependency-expressed-through","errorCode":null,"errorMessage":"Unsatisfied dependency expressed through {}","messagePattern":"Unsatisfied dependency expressed through (.+?)","errorType":"exception","errorClass":"UnsatisfiedDependencyException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java","lineNumber":767,"sourceCode":"\t\t\t}\n\t\t\tif (value != null) {\n\t\t\t\tReflectionUtils.makeAccessible(field);\n\t\t\t\tfield.set(bean, value);\n\t\t\t}\n\t\t}\n\n\t\tprivate @Nullable Object resolveFieldValue(Field field, Object bean, @Nullable String beanName) {\n\t\t\tDependencyDescriptor desc = new DependencyDescriptor(field, this.required);\n\t\t\tdesc.setContainingClass(bean.getClass());\n\t\t\tSet<String> autowiredBeanNames = new LinkedHashSet<>(2);\n\t\t\tAssert.state(beanFactory != null, \"No BeanFactory available\");\n\t\t\tTypeConverter typeConverter = beanFactory.getTypeConverter();\n\t\t\tObject value;\n\t\t\ttry {\n\t\t\t\tvalue = beanFactory.resolveDependency(desc, beanName, autowiredBeanNames, typeConverter);\n\t\t\t}\n\t\t\tcatch (BeansException ex) {\n\t\t\t\tthrow new UnsatisfiedDependencyException(null, beanName, new InjectionPoint(field), ex);\n\t\t\t}\n\t\t\tsynchronized (this) {\n\t\t\t\tif (!this.cached) {\n\t\t\t\t\tif (value != null || this.required) {\n\t\t\t\t\t\tObject cachedFieldValue = desc;\n\t\t\t\t\t\tregisterDependentBeans(beanName, autowiredBeanNames);\n\t\t\t\t\t\tif (value != null && autowiredBeanNames.size() == 1) {\n\t\t\t\t\t\t\tString autowiredBeanName = autowiredBeanNames.iterator().next();\n\t\t\t\t\t\t\tif (beanFactory.containsBean(autowiredBeanName) &&\n\t\t\t\t\t\t\t\t\tbeanFactory.isTypeMatch(autowiredBeanName, field.getType())) {\n\t\t\t\t\t\t\t\tcachedFieldValue = new ShortcutDependencyDescriptor(desc, autowiredBeanName);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.cachedFieldValue = cachedFieldValue;\n\t\t\t\t\t\tthis.cached = true;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis.cachedFieldValue = null;","sourceCodeStart":749,"sourceCodeEnd":785,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java#L749-L785","documentation":"Thrown as UnsatisfiedDependencyException from AutowiredFieldElement.resolveFieldValue() when beanFactory.resolveDependency() throws a BeansException for an @Autowired field. The exception captures the InjectionPoint (the field) so the user sees which field caused the failure. Common underlying causes are NoSuchBeanDefinitionException or NoUniqueBeanDefinitionException.","triggerScenarios":"An @Autowired field's type cannot be resolved: no bean of that type exists, multiple beans exist without a disambiguating @Qualifier, or a scoped proxy resolution fails. The catch at line 766-768 wraps the BeansException into UnsatisfiedDependencyException referencing the field.","commonSituations":"Declaring @Autowired on an interface with no implementations registered. Forgetting to register a @Component via @ComponentScan. Multiple implementations of an interface without @Primary or @Qualifier. A required bean failing its own creation (cascading failure).","solutions":["Check the nested cause — if NoSuchBeanDefinitionException, register a bean of the required type or mark the field @Autowired(required=false).","If NoUniqueBeanDefinitionException, add @Qualifier(\"beanName\") or designate one implementation @Primary.","Verify @ComponentScan covers the package containing the implementation."],"exampleFix":"// before\n@Autowired\nprivate MyRepository repo; // two implementations exist\n\n// after\n@Autowired\n@Qualifier(\"jpaRepository\")\nprivate MyRepository repo;","handlingStrategy":"try-catch","validationCode":"// Before context refresh, verify beans exist for each @Autowired field type\nfor (Field f : MyBean.class.getDeclaredFields()) {\n    if (f.isAnnotationPresent(Autowired.class)) {\n        String[] names = beanFactory.getBeanNamesForType(f.getType());\n        if (names.length == 0 && f.getAnnotation(Autowired.class).required()) {\n            System.err.println(\"Missing bean for field: \" + f.getName());\n        }\n        if (names.length > 1 && !f.isAnnotationPresent(Qualifier.class)) {\n            System.err.println(\"Ambiguous bean for field: \" + f.getName());\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    context.getBean(MyBean.class);\n} catch (UnsatisfiedDependencyException ex) {\n    InjectionPoint ip = ex.getInjectionPoint();\n    if (ip != null) {\n        System.err.println(\"Failed at field/method: \" + ip.getMember());\n    }\n    Throwable cause = ex.getCause(); // NoSuchBeanDefinitionException etc.\n}","preventionTips":["Always add @Qualifier or @Primary when multiple implementations of an interface exist.","Verify @ComponentScan base packages include all dependency implementations.","Use ApplicationContext.containsBeanDefinition() in tests to check dependencies exist."],"tags":["spring","autowiring","field-injection","dependency-resolution"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}