{"record":{"id":"31f17855b74d80e6","repo":"spring-projects/spring-framework","slug":"s-cannot-be-found-on-s","errorCode":null,"errorMessage":"%s cannot be found on %s","messagePattern":"(.+?) cannot be found on (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanInstanceSupplier.java","lineNumber":407,"sourceCode":"\t/**\n\t * Performs lookup of the {@link Constructor}.\n\t */\n\tprivate static class ConstructorLookup extends ExecutableLookup {\n\n\t\tprivate final Class<?>[] parameterTypes;\n\n\t\tConstructorLookup(Class<?>[] parameterTypes) {\n\t\t\tthis.parameterTypes = parameterTypes;\n\t\t}\n\n\t\t@Override\n\t\tpublic Executable get(RegisteredBean registeredBean) {\n\t\t\tClass<?> beanClass = registeredBean.getMergedBeanDefinition().getBeanClass();\n\t\t\ttry {\n\t\t\t\treturn beanClass.getDeclaredConstructor(this.parameterTypes);\n\t\t\t}\n\t\t\tcatch (NoSuchMethodException ex) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"%s cannot be found on %s\".formatted(this, beanClass.getName()), ex);\n\t\t\t}\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"Constructor with parameter types [%s]\".formatted(toCommaSeparatedNames(this.parameterTypes));\n\t\t}\n\t}\n\n\n\t/**\n\t * Performs lookup of the factory {@link Method}.\n\t */\n\tprivate static class FactoryMethodLookup extends ExecutableLookup {\n\n\t\tprivate final Class<?> declaringClass;\n","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanInstanceSupplier.java#L389-L425","documentation":"Thrown as an IllegalArgumentException when the AOT ConstructorLookup cannot find a declared constructor on the bean class matching the recorded parameter types. The supplier stored the constructor signature at AOT time; at runtime getDeclaredConstructor(parameterTypes) throws NoSuchMethodException, which is wrapped with a message describing the expected parameter types and the target class.","triggerScenarios":"ConstructorLookup.get(registeredBean) calls beanClass.getDeclaredConstructor(parameterTypes) and that exact constructor does not exist. Happens when the bean class was changed (constructor signature altered, removed, made package-private to a different package, or replaced by a factory method) but AOT metadata still references the old signature.","commonSituations":"Refactoring the bean class constructor after AOT metadata was generated; introducing a different Spring version that picks a different constructor; bean class loaded from a different artifact version at runtime than at build time; class with multiple constructors where the intended one was removed; AOT cache not cleaned after a code change.","solutions":["Clean and regenerate AOT/native artifacts so the recorded constructor parameter types match the current bean class.","Confirm the runtime classpath uses the same bean class version as the AOT build (no version drift).","If you intentionally changed the constructor, update @Autowired/@ConstructorBinding and bean definition so Spring resolves to the new constructor.","Add or restore the constructor with the exact parameter types listed in the message.","Run the JVM build first; the same NoSuchMethodException surfaces earlier and points at the class mismatch."],"exampleFix":"// before: AOT recorded constructor (String, int) but class now has (String)\npublic Service(String name, int id) { ... } // changed to\npublic Service(String name) { ... }\n\n// after: rebuild AOT metadata and align the constructor\n./gradlew clean build   // regenerate native/AOT metadata for Service(String)","handlingStrategy":"validation","validationCode":"// Verify the recorded constructor still exists on the bean class\nClass<?> beanClass = registeredBean.getBeanClass();\ntry {\n    beanClass.getDeclaredConstructor(recordedParameterTypes);\n} catch (NoSuchMethodException ex) {\n    throw new IllegalStateException(\"Stale AOT metadata: constructor missing on \" + beanClass, ex);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run a clean build after changing bean constructors so AOT metadata matches.","Pin the same bean class version on the runtime classpath as at AOT build time.","Add a build-time check that constructor signatures referenced by generated code still exist.","Avoid removing or changing visibility of constructors referenced by generated suppliers."],"tags":["spring","aot","constructor","reflection","version-drift"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}