spring-projects/spring-framework · error · IllegalArgumentException
AutowiredAnnotationBeanPostProcessor requires a…
Error message
AutowiredAnnotationBeanPostProcessor requires a ConfigurableListableBeanFactory: {} What it means
IllegalArgumentException from AutowiredAnnotationBeanPostProcessor.setBeanFactory when the supplied BeanFactory is not a ConfigurableListableBeanFactory. This post-processor needs CLBF capabilities (type resolution, dependency descriptors, singletons) to drive @Autowired/@Value injection, so a plain BeanFactory (or ListableBeanFactory) is rejected.
Solutions
- Use a ConfigurableListableBeanFactory implementation (DefaultListableBeanFactory, or an ApplicationContext's internal factory).
- If you wrap the factory, ensure the wrapper implements ConfigurableListableBeanFactory (delegate all methods).
- Prefer bootstrap via GenericApplicationContext / AnnotationConfigApplicationContext, which provide a CLBF and register the post-processor automatically.
Example fix
// before BeanFactory bf = new SomeCustomBeanFactory(); autowiredBPP.setBeanFactory(bf); // IllegalArgumentException // after ConfigurableListableBeanFactory clbf = new DefaultListableBeanFactory(); // ... register definitions ... autowiredBPP.setBeanFactory(clbf);
Defensive patterns
Strategy: type-guard
Validate before calling
// Confirm the factory is CLBF before wiring the post-processor
if (!(beanFactory instanceof ConfigurableListableBeanFactory)) {
throw new IllegalStateException("need ConfigurableListableBeanFactory, got " + beanFactory.getClass());
} Type guard
static boolean isConfigurableListable(BeanFactory bf) {
return bf instanceof ConfigurableListableBeanFactory;
} Prevention
- Bootstrap with GenericApplicationContext/AnnotationConfigApplicationContext to get a CLBF for free.
- Any BeanFactory wrapper must implement ConfigurableListableBeanFactory (full delegation).
- Register AutowiredAnnotationBeanPostProcessor only after the factory is fully configured.
When it happens
Trigger: Manually instantiating AutowiredAnnotationBeanPostProcessor and wiring it into a bare BeanFactory / DefaultListableBeanFactory that is not yet a ConfigurableListableBeanFactory; or passing a custom BeanFactory wrapper that does not implement CLBF.
Common situations: Standalone BeanFactory bootstrap (new DefaultListableBeanFactory()) where CLBF was replaced/Decorated; test harnesses that wrap the factory; misordered post-processor registration before the factory is fully configured.
Related errors
- AdvisorAutoProxyCreator requires a…
- BeanFactory must be set on
- CustomAutowireConfigurer needs to operate on a…
- Element access not supported - for custom ObjectProvider…
- Invalid autowire-marked constructor
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/991491db2cf85ef0.
Report an issue: GitHub.
Appendix: source
Thrown at spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java:270
* @see #setRequiredParameterName(String)
*/
public void setRequiredParameterValue(boolean requiredParameterValue) {
this.requiredParameterValue = requiredParameterValue;
}
public void setOrder(int order) {
this.order = order;
}
@Override
public int getOrder() {
return this.order;
}
@Override
public void setBeanFactory(BeanFactory beanFactory) {
if (!(beanFactory instanceof ConfigurableListableBeanFactory clbf)) {
throw new IllegalArgumentException(
"AutowiredAnnotationBeanPostProcessor requires a ConfigurableListableBeanFactory: " + beanFactory);
}
this.beanFactory = clbf;
this.metadataReaderFactory = MetadataReaderFactory.create(clbf.getBeanClassLoader());
}
@Override
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
// Register externally managed config members on bean definition.
findInjectionMetadata(beanName, beanType, beanDefinition);
// Use opportunity to clear caches which are not needed after singleton instantiation.
// The injectionMetadataCache itself is left intact since it cannot be reliably
// reconstructed in terms of externally managed config members otherwise.
if (beanDefinition.isSingleton()) {
this.candidateConstructorsCache.remove(beanType);
// With actual lookup overrides, keep it intact along with bean definition.View on GitHub (pinned to 69bf83ad71)