{"record":{"id":"5e719b9966d0a28a","repo":"spring-projects/spring-ai","slug":"functional-bean-with-name-s-does-not-exist-in-the","errorCode":null,"errorMessage":"Functional bean with name %s does not exist in the context.","messagePattern":"Functional bean with name (.+?) does not exist in the context\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-model/src/main/java/org/springframework/ai/tool/resolution/TypeResolverHelper.java","lineNumber":151,"sourceCode":"\t\tif (functionType.resolve() != null) {\n\t\t\treturn functionType;\n\t\t}\n\n\t\t// Handle root bean definitions with factory methods\n\t\tif (beanDefinition instanceof RootBeanDefinition rootBeanDefinition) {\n\t\t\treturn resolveRootBeanDefinitionType(applicationContext, rootBeanDefinition);\n\t\t}\n\n\t\t// Handle @Component beans\n\t\treturn resolveComponentBeanType(applicationContext, beanDefinition, beanName);\n\t}\n\n\tprivate static BeanDefinition getBeanDefinition(GenericApplicationContext applicationContext, String beanName) {\n\t\ttry {\n\t\t\treturn applicationContext.getBeanDefinition(beanName);\n\t\t}\n\t\tcatch (NoSuchBeanDefinitionException ex) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Functional bean with name \" + beanName + \" does not exist in the context.\");\n\t\t}\n\t}\n\n\tprivate static ResolvableType resolveRootBeanDefinitionType(GenericApplicationContext applicationContext,\n\t\t\tRootBeanDefinition rootBeanDefinition) {\n\n\t\tClass<?> factoryClass;\n\t\tboolean isStatic;\n\n\t\tif (rootBeanDefinition.getFactoryBeanName() != null) {\n\t\t\tfactoryClass = applicationContext.getBeanFactory().getType(rootBeanDefinition.getFactoryBeanName());\n\t\t\tisStatic = false;\n\t\t}\n\t\telse {\n\t\t\tfactoryClass = rootBeanDefinition.getBeanClass();\n\t\t\tisStatic = true;\n\t\t}","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/spring-ai-model/src/main/java/org/springframework/ai/tool/resolution/TypeResolverHelper.java#L133-L169","documentation":"Thrown when TypeResolverHelper needs to inspect a bean definition to resolve a functional bean's tool types, but the Spring context has no bean registered under the given name. It converts Spring's NoSuchBeanDefinitionException into an IllegalArgumentException naming the missing functional bean.","triggerScenarios":"Calling tool resolution for a functional bean (e.g. FunctionCallback wrapper over a @Bean Function/Supplier) where the beanName passed to getBeanDefinition is not registered in the GenericApplicationContext — e.g. a typo in the bean name, the bean defined in a different context/profile, or the functional bean never registered.","commonSituations":"Renaming or removing a @Bean function while ToolCallbacks still reference the old name; beans defined in a child context or missing @Configuration scan; conditional bean (@ConditionalOnProperty) not created at runtime; typos when passing bean names programmatically.","solutions":["Verify the bean name matches exactly the @Bean method name registered in the GenericApplicationContext","Check that the configuration class defining the functional bean is actually scanned/registered in the same context","Confirm no @Conditional annotation or active profile is preventing the bean from being created","Catch NoSuchBeanDefinitionException earlier or use applicationContext.containsBeanDefinition(beanName) before resolution"],"exampleFix":"// before\nToolCallbacks.from(applicationContext, \"fucntionBean\");\n// after\nif (applicationContext.containsBeanDefinition(\"functionBean\")) {\n    ToolCallbacks.from(applicationContext, \"functionBean\");\n}","handlingStrategy":"validation","validationCode":"if (!applicationContext.containsBeanDefinition(beanName)) {\n    throw new IllegalStateException(\"Bean '\" + beanName + \"' is not registered; check @Bean name and context\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep tool bean names in constants shared between definition and lookup","Add a context startup test that asserts all tool beans exist","Avoid conditional registration for beans referenced by name in tool resolution"],"tags":["spring","bean-resolution","configuration"],"backgroundTag":"resource-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"}