spring-projects/spring-framework · error · BeanCreationException
Injection of autowired dependencies failed for class
Error message
Injection of autowired dependencies failed for class [{}] What it means
Thrown by the public processInjection(Object bean) method — used for manual/direct injection outside the normal container lifecycle — when injection fails with a non-BeanCreationException Throwable. This is the native API counterpart of error 203; it includes the class name in the message because the bean name may be null (the method accepts a raw object).
Solutions
- Inspect the nested cause (ex.getCause()) for the real failure — it is often a NoSuchBeanDefinitionException or UnsatisfiedDependencyException.
- Ensure all required dependencies are available in the BeanFactory before calling processInjection.
- Prefer registering the object as a Spring bean instead of manual processInjection, so the full container lifecycle applies.
Example fix
// before
MyBean bean = new MyBean();
postProcessor.processInjection(bean); // fails if deps missing
// after
// Register as a proper bean so dependencies resolve via container
@Bean
MyBean myBean() { return new MyBean(); } Defensive patterns
Strategy: try-catch
Validate before calling
// Before manual injection, verify all @Autowired dependencies are resolvable
Class<?> clazz = bean.getClass();
for (Field f : clazz.getDeclaredFields()) {
if (f.isAnnotationPresent(Autowired.class)) {
Class<?> type = f.getType();
if (beanFactory.getBeanNamesForType(type).length == 0
&& f.getAnnotation(Autowired.class).required()) {
// dependency will fail — register it first
}
}
} Try / catch
try {
postProcessor.processInjection(myBean);
} catch (BeanCreationException ex) {
// message: "Injection of autowired dependencies failed for class [...]"
Throwable cause = ex.getCause();
log.error("Manual injection failed", cause);
} Prevention
- Prefer declaring the object as a Spring bean over manual processInjection.
- Verify all dependencies exist in the BeanFactory before calling processInjection.
- Use processInjection only for edge cases like third-party objects, and always wrap in try-catch.
When it happens
Trigger: Calling autowiredAnnotationBeanPostProcessor.processInjection(myObject) on a manually created object where one of its @Autowired fields/methods cannot be resolved (missing bean, type mismatch, or a reflective error).
Common situations: Using @Autowired on objects created outside Spring (e.g., in a test harness or legacy integration) via processInjection. Manually wiring a non-Spring-managed object that has missing or ambiguous dependencies.
Related errors
- Injection of autowired dependencies failed
- Invalid autowire-marked constructors
- No unique bean definition
- Specified field type [
- Specified parameter type [
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/cd32cf3643d55009.
Report an issue: GitHub.
Appendix: source
Thrown at spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java:522
/**
* <em>Native</em> processing method for direct calls with an arbitrary target
* instance, resolving all of its fields and methods which are annotated with
* one of the configured 'autowired' annotation types.
* @param bean the target instance to process
* @throws BeanCreationException if autowiring failed
* @see #setAutowiredAnnotationTypes(Set)
*/
public void processInjection(Object bean) throws BeanCreationException {
Class<?> clazz = bean.getClass();
InjectionMetadata metadata = findAutowiringMetadata(clazz.getName(), clazz, null);
try {
metadata.inject(bean, null, null);
}
catch (BeanCreationException ex) {
throw ex;
}
catch (Throwable ex) {
throw new BeanCreationException(
"Injection of autowired dependencies failed for class [" + clazz + "]", ex);
}
}
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, @Nullable PropertyValues pvs) {
// Fall back to class name as cache key, for backwards compatibility with custom callers.
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
// Quick check on the concurrent map first, with minimal locking.
InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
if (InjectionMetadata.needsRefresh(metadata, clazz)) {
synchronized (this.injectionMetadataCache) {
metadata = this.injectionMetadataCache.get(cacheKey);
if (InjectionMetadata.needsRefresh(metadata, clazz)) {
if (metadata != null) {
metadata.clear(pvs);
}
metadata = buildAutowiringMetadata(clazz);
this.injectionMetadataCache.put(cacheKey, metadata);View on GitHub (pinned to 69bf83ad71)