spring-projects/spring-framework · error · BeanCreationException

Injection of autowired dependencies failed

Error message

Injection of autowired dependencies failed

What it means

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.

Solutions

  1. Inspect the cause chain (ex.getCause()) — the real exception is nested; address the root throwable.
  2. If the cause is InaccessibleObjectException, add --add-opens JVM flags or ensure the field/method is accessible.
  3. If the cause is a dependency construction failure, fix that bean's creation logic first.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    context.refresh(); // or context.getBean(MyBean.class);
} catch (BeanCreationException ex) {
    Throwable cause = ex.getCause();
    // cause is the non-BeansException throwable from injection
    // e.g., InaccessibleObjectException, IllegalArgumentException
    log.error("Injection failed for bean: {}", ex.getBeanName(), cause);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09). Data as JSON: /api/errors/95253f4731c7f6c8. Report an issue: GitHub.

Appendix: source

Thrown at spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java:499

				catch (IllegalStateException ex) {
					throw new BeanCreationException(beanName, "Lookup method resolution failed", ex);
				}
			}
			this.lookupMethodsChecked.add(beanName);
		}
	}

	@Override
	public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) {
		InjectionMetadata metadata = findAutowiringMetadata(beanName, bean.getClass(), pvs);
		try {
			metadata.inject(bean, beanName, pvs);
		}
		catch (BeanCreationException ex) {
			throw ex;
		}
		catch (Throwable ex) {
			throw new BeanCreationException(beanName, "Injection of autowired dependencies failed", ex);
		}
		return pvs;
	}

	/**
	 * <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);
		}

View on GitHub (pinned to 69bf83ad71)