{"id":"adb362e61d893c5d","repo":"spring-projects/spring-framework","slug":"unable-to-locate-method-on-bean","errorCode":null,"errorMessage":"Unable to locate method [{}] on bean [{}]","messagePattern":"Unable to locate method \\[(.+?)\\] on bean \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java","lineNumber":78,"sourceCode":"\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;\n\t}\n\n\t@Override\n\tpublic boolean isSingleton() {\n\t\treturn true;","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java#L60-L96","documentation":"Thrown by MethodLocatingFactoryBean.setBeanFactory after the bean type was resolved successfully but BeanUtils.resolveSignature(methodName, beanClass) returned null, meaning no method matching the given signature string could be found. resolveSignature accepts either a simple name or a fully-qualified signature with argument types, and a mismatch in either the name or the parameter type list yields this error. It is a configuration-time validation failure.","triggerScenarios":"Calling setMethodName with a method that doesn't exist on the target bean's class; using a signature string with wrong fully-qualified parameter type names (e.g. 'java.lang.string' lowercase); overloads where resolveSignature cannot disambiguate without explicit args; the method exists only on a different class than the resolved bean type.","commonSituations":"Renaming a method in the target class but forgetting to update the XML AOP config; pointing at an interface-implementing class but specifying a method declared only on another implementation; copy-paste errors in overloaded method signatures; using primitive vs boxed type names inconsistently in the signature.","solutions":["Check the resolved bean's actual Class (enable debug logging on org.springframework.beans.BeanUtils) and confirm the method name exists on exactly that class.","If overloaded, supply a full signature with argument types, e.g. 'doWork(int,java.lang.String)' using correct fully-qualified names (capitalize type names correctly).","Verify parameter types: use fully-qualified class names and remember primitives are lowercase (int) while boxed types are java.lang.Integer.","Rebuild/redeploy to ensure the class on the classpath matches the config (stale class file vs new config)."],"exampleFix":"// before\n<property name=\"methodName\" value=\"doWork(int,java.lang.string)\"/>  // wrong casing\n\n// after\n<property name=\"methodName\" value=\"doWork(int,java.lang.String)\"/>  // correct FQN","handlingStrategy":"validation","validationCode":"Class<?> beanClass = bf.getType(\"myService\");\nString methodName = \"doWork(int,java.lang.String)\";\nif (org.springframework.beans.BeanUtils.resolveSignature(methodName, beanClass) == null) {\n  throw new IllegalStateException(\n    \"Method '\" + methodName + \"' not found on \" + beanClass + \"; verify name and fully-qualified arg types\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  // configure MethodLocatingFactoryBean\n} catch (IllegalArgumentException ex) {\n  if (ex.getMessage().contains(\"Unable to locate method\")) {\n    // log method + bean, point user at the renamed/missing method\n  }\n  throw ex;\n}","preventionTips":["When overloaded, always supply a full signature with fully-qualified parameter types; remember primitives are lowercase.","Run a unit test that asserts resolveSignature returns non-null for every XML-configured methodName against the real target class.","Rename methods and their AOP config together in the same commit."],"tags":["spring-aop","reflection","configuration","method-resolution"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}