{"record":{"id":"d86030dfd3121efe","repo":"paascloud/paascloud-master","slug":"error-d86030","errorCode":null,"errorMessage":"验证码生成器不存在","messagePattern":"验证码生成器不存在","errorType":"validation","errorClass":"ValidateCodeException","httpStatus":400,"severity":"error","filePath":"paascloud-common/paascloud-security-core/src/main/java/com/paascloud/security/core/validate/code/impl/AbstractValidateCodeProcessor.java","lineNumber":75,"sourceCode":"\t * @throws Exception the exception\n\t */\n\t@Override\n\tpublic void create(ServletWebRequest request) throws Exception {\n\t\tC validateCode = generate(request);\n\t\tsave(request, validateCode);\n\t\tsend(request, validateCode);\n\t}\n\n\t/**\n\t * 生成校验码\n\t */\n\t@SuppressWarnings(\"unchecked\")\n\tprivate C generate(ServletWebRequest request) {\n\t\tString type = getValidateCodeType().toString().toLowerCase();\n\t\tString generatorName = type + ValidateCodeGenerator.class.getSimpleName();\n\t\tValidateCodeGenerator validateCodeGenerator = validateCodeGenerators.get(generatorName);\n\t\tif (validateCodeGenerator == null) {\n\t\t\tthrow new ValidateCodeException(\"验证码生成器\" + generatorName + \"不存在\");\n\t\t}\n\t\treturn (C) validateCodeGenerator.generate(request);\n\t}\n\n\t/**\n\t * 保存校验码\n\t */\n\tprivate void save(ServletWebRequest request, C validateCode) {\n\t\tValidateCode code = new ValidateCode(validateCode.getCode(), validateCode.getExpireTime());\n\t\tvalidateCodeRepository.save(request, code, getValidateCodeType());\n\t}\n\n\t/**\n\t * 发送校验码，由子类实现\n\t *\n\t * @param request      the request\n\t * @param validateCode the validate code\n\t *","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-common/paascloud-security-core/src/main/java/com/paascloud/security/core/validate/code/impl/AbstractValidateCodeProcessor.java#L57-L93","documentation":"AbstractValidateCodeProcessor.generate resolves a ValidateCodeGenerator from the Spring context by naming convention: <type lowercase> + 'ValidateCodeGenerator' (e.g. 'smsValidateCodeGenerator'). If no bean with that name is registered, ValidateCodeException '验证码生成器xxx不存在' is thrown before any code can be generated.","triggerScenarios":"Requesting a validate code of a type whose generator bean was never defined — adding a new ValidateCodeType without a matching XxxValidateCodeGenerator @Component, or the default generator being overridden/removed.","commonSituations":"Custom code type (e.g. 'email') added but no EmailValidateCodeGenerator bean; configuration class excluding the generator from component scan; bean name mismatch due to custom @Component(\"name\").","solutions":["Define a bean implementing ValidateCodeGenerator named <type>ValidateCodeGenerator","Verify the generator is in a component-scanned package","Confirm the bean name matches the convention exactly (lowercase type + 'ValidateCodeGenerator')","If relying on the demo/ImageValidateCodeGenerator defaults, ensure SecurityCoreConfig is imported"],"exampleFix":"// before\n// no generator for 'email' type -> throw\n// after\n@Component(\"emailValidateCodeGenerator\")\npublic class EmailValidateCodeGenerator implements ValidateCodeGenerator {\n    public ValidateCode generate(ServletWebRequest request) { /* ... */ }\n}","handlingStrategy":"validation","validationCode":"String genName = type.toLowerCase() + \"ValidateCodeGenerator\";\nif (!applicationContext.containsBean(genName)) {\n    throw new IllegalStateException(\"缺少bean: \" + genName);\n}","typeGuard":null,"tryCatchPattern":"try { processor.validate(request); } catch (ValidateCodeException e) { model.addAttribute(\"codeError\", e.getMessage()); return \"login\"; }","preventionTips":["When adding a ValidateCodeType, always add the matching generator bean","Verify bean names match <type>ValidateCodeGenerator exactly","Add a startup check listing registered generators"],"tags":["validation-code","spring","missing-bean"],"backgroundTag":"resource-not-found","analyzedSha":"781281a9503332ed3cef44ea618349d14230a127","analyzedAt":"2026-09-10T10:59:02.070Z","contentChangedAt":"2026-09-10T10:59:02.070Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}