{"record":{"id":"74c86c9c551b5853","repo":"jeecgboot/JeecgBoot","slug":"classname-not-found","errorCode":null,"errorMessage":"{className} not found!","messagePattern":"(.+?) not found!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/MyClassLoader.java","lineNumber":17,"sourceCode":"package org.jeecg.common.util;\n\nimport org.jeecg.common.constant.SymbolConstant;\n\n/**\n * @Author  张代浩\n */\npublic class MyClassLoader extends ClassLoader {\n\tpublic static Class getClassByScn(String className) {\n\t\tClass myclass = null;\n\t\ttry {\n\t\t\t//update-begin---author:scott ---date:20260416  for：【PR#9538】Class.forName使用上下文类加载器，增强部署兼容性-----------\n\t\t\tmyclass = Class.forName(className, true, Thread.currentThread().getContextClassLoader());\n\t\t\t//update-end---author:scott ---date:20260416  for：【PR#9538】Class.forName使用上下文类加载器，增强部署兼容性-----------\n\t\t} catch (ClassNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t\tthrow new RuntimeException(className+\" not found!\");\n\t\t}\n\t\treturn myclass;\n\t}\n\n    /**\n     * 获得类的全名，包括包名\n     * @param object\n     * @return\n     */\n\tpublic static String getPackPath(Object object) {\n\t\t// 检查用户传入的参数是否为空\n\t\tif (object == null) {\n\t\t\tthrow new java.lang.IllegalArgumentException(\"参数不能为空！\");\n\t\t}\n\t\t// 获得类的全名，包括包名\n\t\tString clsName = object.getClass().getName();\n\t\treturn clsName;\n\t}","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/MyClassLoader.java#L1-L35","documentation":"Thrown by MyClassLoader.getClassByScn when Class.forName cannot find the requested class on the context classloader. The ClassNotFoundException is caught, printed, and rethrown as a RuntimeException with the message '{className} not found!'. This is a generic dynamic-class-loading utility, not security-gated.","triggerScenarios":"Calling MyClassLoader.getClassByScn(fqcn) with a fully-qualified class name that is absent from the runtime classpath, or when the thread context classloader cannot see the class (common in fat-jar / layered deployments).","commonSituations":"Typo or stale class name in a configuration table; the module containing the class was not included as a dependency; class removed or relocated in a framework upgrade; context classloader differs in a Spring Boot executable jar vs IDE.","solutions":["Verify the fully-qualified class name is correct and the class is present in a deployed jar/module.","Ensure the module declaring the class is on the runtime classpath (add the Maven dependency, rebuild).","If the issue is classloader visibility in a packaged jar, confirm the thread context classloader can see the class; load via the specific classloader that owns it.","Catch RuntimeException at the call site and degrade gracefully if dynamic loading is optional."],"exampleFix":"// before\nClass<?> clazz = MyClassLoader.getClassByScn(config.getClassName());\n\n// after\nClass<?> clazz;\ntry {\n    clazz = MyClassLoader.getClassByScn(config.getClassName());\n} catch (RuntimeException e) {\n    log.error(\"动态类 [{}] 未找到，请检查类名与依赖\", config.getClassName(), e);\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (className == null || className.isBlank()) {\n    throw new IllegalArgumentException(\"className 不能为空\");\n}","typeGuard":"null","tryCatchPattern":"try {\n    Class<?> clazz = MyClassLoader.getClassByScn(fqcn);\n} catch (RuntimeException e) {\n    log.error(\"类 [{}] 未找到\", fqcn, e);\n    throw new IllegalArgumentException(\"指定的类不存在: \" + fqcn, e);\n}","preventionTips":["Verify class names against the deployed classpath, not just the IDE.","Prefer explicit dependencies over dynamic class loading where possible.","Validate configurable class names at startup to fail fast."],"tags":["reflection","class-loading","classpath","runtime-exception"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}