{"id":"498a5b5686fda34c","repo":"spring-projects/spring-framework","slug":"failed-to-load-class-from-classloader","errorCode":null,"errorMessage":"Failed to load Class [{}] from ClassLoader [{}]","messagePattern":"Failed to load Class \\[(.+?)\\] from ClassLoader \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGenerator.java","lineNumber":182,"sourceCode":"\t\t\t\t\t.collect(CodeBlock.joining(\", \"));\n\t\t\tcode.addStatement(format, BEAN_DEFINITION_VARIABLE, arguments);\n\t\t}\n\t}\n\n\tprivate void addInitDestroyHint(Class<?> beanUserClass, String methodName) {\n\t\tClass<?> methodDeclaringClass = beanUserClass;\n\n\t\t// Parse fully-qualified method name if necessary.\n\t\tint indexOfDot = methodName.lastIndexOf('.');\n\t\tif (indexOfDot > 0) {\n\t\t\tString className = methodName.substring(0, indexOfDot);\n\t\t\tmethodName = methodName.substring(indexOfDot + 1);\n\t\t\tif (!beanUserClass.getName().equals(className)) {\n\t\t\t\ttry {\n\t\t\t\t\tmethodDeclaringClass = ClassUtils.forName(className, beanUserClass.getClassLoader());\n\t\t\t\t}\n\t\t\t\tcatch (Throwable ex) {\n\t\t\t\t\tthrow new IllegalStateException(\"Failed to load Class [\" + className +\n\t\t\t\t\t\t\t\"] from ClassLoader [\" + beanUserClass.getClassLoader() + \"]\", ex);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tMethod method = ReflectionUtils.findMethod(methodDeclaringClass, methodName);\n\t\tif (method != null) {\n\t\t\tthis.hints.reflection().registerMethod(method, ExecutableMode.INVOKE);\n\t\t\tMethod publiclyAccessibleMethod = ClassUtils.getPubliclyAccessibleMethodIfPossible(method, beanUserClass);\n\t\t\tif (!publiclyAccessibleMethod.equals(method)) {\n\t\t\t\tthis.hints.reflection().registerMethod(publiclyAccessibleMethod, ExecutableMode.INVOKE);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate void addConstructorArgumentValues(CodeBlock.Builder code, BeanDefinition beanDefinition) {\n\t\tConstructorArgumentValues constructorValues = beanDefinition.getConstructorArgumentValues();\n\t\tMap<Integer, ValueHolder> indexedValues = constructorValues.getIndexedArgumentValues();","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGenerator.java#L164-L200","documentation":"During AOT bean-definition code generation, BeanDefinitionPropertiesCodeGenerator parses a fully-qualified factory/lookup method name; if the class portion of that name cannot be loaded by the bean class's ClassLoader, this IllegalStateException is thrown. It indicates a method reference points at a type that is not visible to the bean's classloader at AOT time.","triggerScenarios":"A bean definition's factory-method or overrides reference a fully-qualified method whose declaring class (the prefix before the last '.') is absent from the bean class's ClassLoader during AOT processing.","commonSituations":"Class removed/renamed in a dependency bump but bean XML/registration still references the old FQN; multi-module build where a class is on the compile classpath but not the AOT/runtime classpath; bean defined in XML with a stale factory-method attribute.","solutions":["Correct the class name in the factory-method/override reference to the current FQN.","Add the missing class/module to the classpath used for AOT processing.","Remove the obsolete bean definition or method-override entry."],"exampleFix":"<!-- before -->\n<bean class=\"com.acme.OldService\" factory-method=\"com.acme.removed.Helper.create\"/>\n<!-- after -->\n<bean class=\"com.acme.OldService\" factory-method=\"com.acme.Helper.create\"/>","handlingStrategy":"validation","validationCode":"int dot = methodName.lastIndexOf('.');\nif (dot > 0) {\n  String cls = methodName.substring(0, dot);\n  if (!ClassUtils.isPresent(cls, beanClass.getClassLoader())) {\n    throw new IllegalStateException(\"Class \" + cls + \" not loadable by \" + beanClass.getClassLoader());\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep factory-method FQNs in sync with dependency class names.","Ensure all referenced classes are on the AOT classpath.","Prefer Class-based over String-based method references where possible."],"tags":["spring","aot","native","classloader","classloading"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}