{"record":{"id":"95253f4731c7f6c8","repo":"spring-projects/spring-framework","slug":"injection-of-autowired-dependencies-failed","errorCode":null,"errorMessage":"Injection of autowired dependencies failed","messagePattern":"Injection of autowired dependencies failed","errorType":"exception","errorClass":"BeanCreationException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java","lineNumber":499,"sourceCode":"\t\t\t\tcatch (IllegalStateException ex) {\n\t\t\t\t\tthrow new BeanCreationException(beanName, \"Lookup method resolution failed\", ex);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.lookupMethodsChecked.add(beanName);\n\t\t}\n\t}\n\n\t@Override\n\tpublic PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) {\n\t\tInjectionMetadata metadata = findAutowiringMetadata(beanName, bean.getClass(), pvs);\n\t\ttry {\n\t\t\tmetadata.inject(bean, beanName, pvs);\n\t\t}\n\t\tcatch (BeanCreationException ex) {\n\t\t\tthrow ex;\n\t\t}\n\t\tcatch (Throwable ex) {\n\t\t\tthrow new BeanCreationException(beanName, \"Injection of autowired dependencies failed\", ex);\n\t\t}\n\t\treturn pvs;\n\t}\n\n\t/**\n\t * <em>Native</em> processing method for direct calls with an arbitrary target\n\t * instance, resolving all of its fields and methods which are annotated with\n\t * one of the configured 'autowired' annotation types.\n\t * @param bean the target instance to process\n\t * @throws BeanCreationException if autowiring failed\n\t * @see #setAutowiredAnnotationTypes(Set)\n\t */\n\tpublic void processInjection(Object bean) throws BeanCreationException {\n\t\tClass<?> clazz = bean.getClass();\n\t\tInjectionMetadata metadata = findAutowiringMetadata(clazz.getName(), clazz, null);\n\t\ttry {\n\t\t\tmetadata.inject(bean, null, null);\n\t\t}","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java#L481-L517","documentation":"Thrown by postProcessProperties() — the standard BeanPostProcessor callback — when metadata.inject() fails with a Throwable that is not already a BeanCreationException. Any unexpected runtime exception during field or method injection (NullPointerException, IllegalStateException from custom logic, reflective failures) gets wrapped here so the bean name is included in the diagnostic.","triggerScenarios":"A field or setter annotated with @Autowired has an injection target whose resolution throws a non-BeansException Throwable — e.g., a custom TypeConverter throws IllegalArgumentException, or the target bean's constructor throws a RuntimeException during eager resolution.","commonSituations":"A dependency bean fails to construct (its own constructor throws). A custom PropertyEditor/TypeConverter throws during conversion. Reflective access failures on Java modules (InaccessibleObjectException). Circular dependency edge cases that surface as IllegalStateException.","solutions":["Inspect the cause chain (ex.getCause()) — the real exception is nested; address the root throwable.","If the cause is InaccessibleObjectException, add --add-opens JVM flags or ensure the field/method is accessible.","If the cause is a dependency construction failure, fix that bean's creation logic first."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    context.refresh(); // or context.getBean(MyBean.class);\n} catch (BeanCreationException ex) {\n    Throwable cause = ex.getCause();\n    // cause is the non-BeansException throwable from injection\n    // e.g., InaccessibleObjectException, IllegalArgumentException\n    log.error(\"Injection failed for bean: {}\", ex.getBeanName(), cause);\n}","preventionTips":["Inspect the nested cause of BeanCreationException to find the real injection failure.","Add --add-opens JVM args if InaccessibleObjectException appears as the cause.","Ensure dependency beans are constructible before they are injected into others."],"tags":["spring","autowiring","injection","bean-creation"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}