{"record":{"id":"cdaf4d8cf3cdda82","repo":"spring-projects/spring-framework","slug":"customautowireconfigurer-needs-to-operate-on-a-def","errorCode":null,"errorMessage":"CustomAutowireConfigurer needs to operate on a DefaultListableBeanFactory","messagePattern":"CustomAutowireConfigurer needs to operate on a DefaultListableBeanFactory","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurer.java","lineNumber":94,"sourceCode":"\t * when autowiring beans. Each element of the provided set may\n\t * be either a Class instance or a String representation of the\n\t * fully-qualified class name of the custom annotation.\n\t * <p>Note that any annotation that is itself annotated with Spring's\n\t * {@link org.springframework.beans.factory.annotation.Qualifier}\n\t * does not require explicit registration.\n\t * @param customQualifierTypes the custom types to register\n\t */\n\tpublic void setCustomQualifierTypes(Set<?> customQualifierTypes) {\n\t\tthis.customQualifierTypes = customQualifierTypes;\n\t}\n\n\n\t@Override\n\t@SuppressWarnings(\"unchecked\")\n\tpublic void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {\n\t\tif (this.customQualifierTypes != null) {\n\t\t\tif (!(beanFactory instanceof DefaultListableBeanFactory dlbf)) {\n\t\t\t\tthrow new IllegalStateException(\n\t\t\t\t\t\t\"CustomAutowireConfigurer needs to operate on a DefaultListableBeanFactory\");\n\t\t\t}\n\t\t\tif (!(dlbf.getAutowireCandidateResolver() instanceof QualifierAnnotationAutowireCandidateResolver)) {\n\t\t\t\tdlbf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());\n\t\t\t}\n\t\t\tQualifierAnnotationAutowireCandidateResolver resolver =\n\t\t\t\t\t(QualifierAnnotationAutowireCandidateResolver) dlbf.getAutowireCandidateResolver();\n\t\t\tfor (Object value : this.customQualifierTypes) {\n\t\t\t\tClass<? extends Annotation> customType = null;\n\t\t\t\tif (value instanceof Class) {\n\t\t\t\t\tcustomType = (Class<? extends Annotation>) value;\n\t\t\t\t}\n\t\t\t\telse if (value instanceof String className) {\n\t\t\t\t\tcustomType = (Class<? extends Annotation>) ClassUtils.resolveClassName(className, this.beanClassLoader);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\t\"Invalid value [\" + value + \"] for custom qualifier type: needs to be Class or String.\");","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurer.java#L76-L112","documentation":"Thrown by CustomAutowireConfigurer.postProcessBeanFactory() when the BeanFactory it receives is not an instance of DefaultListableBeanFactory. CustomAutowireConfigurer must install custom qualifier types on the AutowireCandidateResolver, which is only available on DefaultListableBeanFactory. Any other BeanFactory type is incompatible.","triggerScenarios":"Registering CustomAutowireConfigurer as a BeanFactoryPostProcessor in a context whose underlying BeanFactory is not a DefaultListableBeanFactory (e.g., a custom BeanFactory implementation or certain test fixtures).","commonSituations":"Using a custom ApplicationContext with a non-standard BeanFactory. Manually wiring CustomAutowireConfigurer against a SimpleJndiBeanFactory or StaticListableBeanFactory. Test setups with mock/custom BeanFactory implementations.","solutions":["Use a context backed by DefaultListableBeanFactory (GenericApplicationContext, AnnotationConfigApplicationContext, ClassPathXmlApplicationContext all use it by default).","If using a custom BeanFactory, extend DefaultListableBeanFactory rather than implementing BeanFactory from scratch.","Remove CustomAutowireConfigurer if custom qualifier types are not actually needed — @Qualifier works without it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify the BeanFactory type before deploying CustomAutowireConfigurer\nif (!(beanFactory instanceof DefaultListableBeanFactory)) {\n    throw new IllegalStateException(\n        \"CustomAutowireConfigurer requires DefaultListableBeanFactory, got: \"\n        + beanFactory.getClass().getName());\n}","typeGuard":"// Type guard: check before using CustomAutowireConfigurer\nif (beanFactory instanceof DefaultListableBeanFactory dlbf) {\n    CustomAutowireConfigurer configurer = new CustomAutowireConfigurer();\n    configurer.setCustomQualifierTypes(Set.of(MyQualifier.class));\n    configurer.postProcessBeanFactory(dlbf);\n} else {\n    // use standard ApplicationContext instead\n}","tryCatchPattern":null,"preventionTips":["Use standard Spring ApplicationContext types which are backed by DefaultListableBeanFactory.","If using a custom context, ensure its BeanFactory extends DefaultListableBeanFactory.","Avoid CustomAutowireConfigurer unless you truly need custom qualifier types — @Qualifier works out of the box."],"tags":["spring","custom-autowire","bean-factory","configuration"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}