{"record":{"id":"991491db2cf85ef0","repo":"spring-projects/spring-framework","slug":"autowiredannotationbeanpostprocessor-requires-a-co","errorCode":null,"errorMessage":"AutowiredAnnotationBeanPostProcessor requires a ConfigurableListableBeanFactory: {}","messagePattern":"AutowiredAnnotationBeanPostProcessor requires a ConfigurableListableBeanFactory: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java","lineNumber":270,"sourceCode":"\t * @see #setRequiredParameterName(String)\n\t */\n\tpublic void setRequiredParameterValue(boolean requiredParameterValue) {\n\t\tthis.requiredParameterValue = requiredParameterValue;\n\t}\n\n\tpublic void setOrder(int order) {\n\t\tthis.order = order;\n\t}\n\n\t@Override\n\tpublic int getOrder() {\n\t\treturn this.order;\n\t}\n\n\t@Override\n\tpublic void setBeanFactory(BeanFactory beanFactory) {\n\t\tif (!(beanFactory instanceof ConfigurableListableBeanFactory clbf)) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"AutowiredAnnotationBeanPostProcessor requires a ConfigurableListableBeanFactory: \" + beanFactory);\n\t\t}\n\t\tthis.beanFactory = clbf;\n\t\tthis.metadataReaderFactory = MetadataReaderFactory.create(clbf.getBeanClassLoader());\n\t}\n\n\n\t@Override\n\tpublic void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {\n\t\t// Register externally managed config members on bean definition.\n\t\tfindInjectionMetadata(beanName, beanType, beanDefinition);\n\n\t\t// Use opportunity to clear caches which are not needed after singleton instantiation.\n\t\t// The injectionMetadataCache itself is left intact since it cannot be reliably\n\t\t// reconstructed in terms of externally managed config members otherwise.\n\t\tif (beanDefinition.isSingleton()) {\n\t\t\tthis.candidateConstructorsCache.remove(beanType);\n\t\t\t// With actual lookup overrides, keep it intact along with bean definition.","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java#L252-L288","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nBeanFactory bf = new SomeCustomBeanFactory();\nautowiredBPP.setBeanFactory(bf); // IllegalArgumentException\n\n// after\nConfigurableListableBeanFactory clbf = new DefaultListableBeanFactory();\n// ... register definitions ...\nautowiredBPP.setBeanFactory(clbf);","handlingStrategy":"type-guard","validationCode":"// Confirm the factory is CLBF before wiring the post-processor\nif (!(beanFactory instanceof ConfigurableListableBeanFactory)) {\n    throw new IllegalStateException(\"need ConfigurableListableBeanFactory, got \" + beanFactory.getClass());\n}","typeGuard":"static boolean isConfigurableListable(BeanFactory bf) {\n    return bf instanceof ConfigurableListableBeanFactory;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["dependency-injection","bean-post-processor","bean-factory"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}