{"id":"75afe47641fb4ca5","repo":"spring-projects/spring-framework","slug":"can-t-determine-type-of-bean-with-name","errorCode":null,"errorMessage":"Can't determine type of bean with name '{}'","messagePattern":"Can't determine type of bean with name '(.+?)'","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java","lineNumber":73,"sourceCode":"\t * <p>This property is required.\n\t * @param methodName the name of the {@link Method} to locate\n\t */\n\tpublic void setMethodName(String methodName) {\n\t\tthis.methodName = methodName;\n\t}\n\n\t@Override\n\tpublic void setBeanFactory(BeanFactory beanFactory) {\n\t\tif (!StringUtils.hasText(this.targetBeanName)) {\n\t\t\tthrow new IllegalArgumentException(\"Property 'targetBeanName' is required\");\n\t\t}\n\t\tif (!StringUtils.hasText(this.methodName)) {\n\t\t\tthrow new IllegalArgumentException(\"Property 'methodName' is required\");\n\t\t}\n\n\t\tClass<?> beanClass = beanFactory.getType(this.targetBeanName);\n\t\tif (beanClass == null) {\n\t\t\tthrow new IllegalArgumentException(\"Can't determine type of bean with name '\" + this.targetBeanName + \"'\");\n\t\t}\n\t\tthis.method = BeanUtils.resolveSignature(this.methodName, beanClass);\n\n\t\tif (this.method == null) {\n\t\t\tthrow new IllegalArgumentException(\"Unable to locate method [\" + this.methodName +\n\t\t\t\t\t\"] on bean [\" + this.targetBeanName + \"]\");\n\t\t}\n\t}\n\n\n\t@Override\n\tpublic @Nullable Method getObject() throws Exception {\n\t\treturn this.method;\n\t}\n\n\t@Override\n\tpublic Class<Method> getObjectType() {\n\t\treturn Method.class;","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java#L55-L91","documentation":"Thrown by MethodLocatingFactoryBean.setBeanFactory when BeanFactory.getType(targetBeanName) returns null, meaning the container cannot resolve a concrete type for the named bean at FactoryBean initialization time. Spring throws this because it needs a real Class to reflectively locate the target method that this FactoryBean is meant to expose. The error surfaces during context startup (bean initialization), not at runtime use of the located Method.","triggerScenarios":"Configuring a <aop:aspect> or MethodLocatingFactoryBean in XML where the 'targetBeanName' property refers to a bean that is itself an untyped FactoryBean whose getObjectType() returns null, a bean definition that has not been loaded/registered, or a bean name typo. Also triggered when the bean is a scoped proxy whose type cannot be statically determined.","commonSituations":"Migrating XML AOP config and misspelling the target bean name; pointing at an abstract bean or parent bean definition that never gets a concrete type; referencing a FactoryBean (e.g. a third-party one) that does not implement getObjectType() before getObject() runs; circular dependencies that prevent type resolution at the point setBeanFactory fires.","solutions":["Verify the exact spelling and case of 'targetBeanName' against the bean id in the same application context.","Ensure the referenced bean is a concrete bean definition (not abstract) and is registered in the context that owns the MethodLocatingFactoryBean.","If the target is a FactoryBean, confirm its getObjectType() returns a non-null Class at FactoryBean initialization time; implement/fix getObjectType() if it lazily returns null.","Resolve any circular-dependency or parent-context issues that prevent type resolution by marking the target non-lazy or restructuring the dependency graph."],"exampleFix":"// before\n<bean id=\"methodLocator\" class=\"org.springframework.aop.config.MethodLocatingFactoryBean\">\n  <property name=\"targetBeanName\" value=\"servcie\"/>  <!-- typo -->\n  <property name=\"methodName\" value=\"doWork\"/>\n</bean>\n\n// after\n<bean id=\"methodLocator\" class=\"org.springframework.aop.config.MethodLocatingFactoryBean\">\n  <property name=\"targetBeanName\" value=\"service\"/>  <!-- matches real bean id -->\n  <property name=\"methodName\" value=\"doWork\"/>\n</bean>","handlingStrategy":"validation","validationCode":"BeanFactory bf = ...; String name = \"myService\";\nClass<?> type = bf.getType(name);\nif (type == null) {\n  throw new IllegalStateException(\n    \"Cannot resolve type for bean '\" + name + \"'; fix the bean definition before wiring MethodLocatingFactoryBean\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep bean ids in a shared constant or enum to avoid typo drift between the bean and its MethodLocatingFactoryBean reference.","If the target is a FactoryBean, implement getObjectType() to return a concrete Class even before getObject() runs.","Wire MethodLocatingFactoryBean beans in the same context that owns the target bean to avoid parent/child resolution gaps."],"tags":["spring-aop","bean-factory","configuration","startup"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}