{"record":{"id":"57fb23b06b4b159f","repo":"spring-projects/spring-ai","slug":"impossible-to-resolve-the-type-of-bean","errorCode":null,"errorMessage":"Impossible to resolve the type of bean ","messagePattern":"Impossible to resolve the type of bean ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-model/src/main/java/org/springframework/ai/tool/resolution/TypeResolverHelper.java","lineNumber":208,"sourceCode":"\t\t\t\telse if (isParamMismatch(uniqueCandidate, candidate)) {\n\t\t\t\t\tuniqueCandidate = null;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn uniqueCandidate;\n\t}\n\n\tprivate static ResolvableType resolveComponentBeanType(GenericApplicationContext applicationContext,\n\t\t\tBeanDefinition beanDefinition, String beanName) {\n\t\tif (beanDefinition.getFactoryMethodName() == null && beanDefinition.getBeanClassName() != null) {\n\t\t\ttry {\n\t\t\t\treturn ResolvableType.forClass(\n\t\t\t\t\t\tClassUtils.forName(beanDefinition.getBeanClassName(), applicationContext.getClassLoader()));\n\t\t\t}\n\t\t\tcatch (ClassNotFoundException ex) {\n\t\t\t\tthrow new IllegalArgumentException(\"Impossible to resolve the type of bean \" + beanName, ex);\n\t\t\t}\n\t\t}\n\t\tthrow new IllegalArgumentException(\"Impossible to resolve the type of bean \" + beanName);\n\t}\n\n\tstatic private Method[] getCandidateMethods(Class<?> factoryClass, RootBeanDefinition mbd) {\n\t\treturn (mbd.isNonPublicAccessAllowed() ? ReflectionUtils.getUniqueDeclaredMethods(factoryClass)\n\t\t\t\t: factoryClass.getMethods());\n\t}\n\n\tstatic private boolean isStaticCandidate(Method method, Class<?> factoryClass) {\n\t\treturn (Modifier.isStatic(method.getModifiers()) && method.getDeclaringClass() == factoryClass);\n\t}\n\n\tstatic private boolean isParamMismatch(Method uniqueCandidate, Method candidate) {\n\t\tint uniqueCandidateParameterCount = uniqueCandidate.getParameterCount();\n\t\tint candidateParameterCount = candidate.getParameterCount();\n\t\treturn (uniqueCandidateParameterCount != candidateParameterCount","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/spring-ai-model/src/main/java/org/springframework/ai/tool/resolution/TypeResolverHelper.java#L190-L226","documentation":"Thrown when resolving a component bean's type fails because the bean's declared class name cannot be loaded from the context's class loader (ClassNotFoundException). Spring cannot determine the bean's Java type, which is required for tool type inference.","triggerScenarios":"resolveBeanType encounters a bean definition with no factory method but a beanClassName that fails ClassUtils.forName — e.g. class removed after config was written, dependency not on runtime classpath, class in a different classloader (fat-jar/reload scenarios).","commonSituations":"Upgrading/downgrading a dependency so a previously referenced class disappears; class referenced only in compile-scope but not runtime scope; hot-reload/devtools classloader mismatches; renaming classes without updating XML/component configuration.","solutions":["Add the missing class's artifact to the runtime classpath (check dependency scope is not 'provided' or missing at runtime)","Update bean definitions/configuration to reference the class's current fully-qualified name","Verify the class is loadable: Class.forName(\"com.example.BeanType\") in the same classloader","Register the bean via a factory method (@Bean) so type resolution doesn't rely on the class name string"],"exampleFix":"// before (beanClassName no longer on classpath)\n@Bean(name = \"toolBean\")  // beanClassName=com.old.Missing\n// after — define with explicit factory method so type is resolvable\n@Bean\npublic MyFunction toolBean() { return new MyFunction(); }","handlingStrategy":"validation","validationCode":"try {\n    ClassUtils.forName(beanDefinition.getBeanClassName(), classLoader);\n} catch (ClassNotFoundException e) {\n    // fix classpath before enabling tool resolution\n}","typeGuard":null,"tryCatchPattern":"try { toolResolution(); } catch (IllegalArgumentException e) {\n    if (e.getCause() instanceof ClassNotFoundException cnfe) { /* restore missing dependency */ }\n}","preventionTips":["Run integration tests with the full runtime classpath","Avoid referencing classes from optional/provided dependencies in bean definitions","Prefer @Bean factory methods over string-based class names"],"tags":["spring","classpath","type-resolution"],"backgroundTag":"class-not-found","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}