paascloud/paascloud-master · error · ValidateCodeException

验证码生成器不存在

Error message

验证码生成器不存在

What it means

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.

Solutions

  1. Define a bean implementing ValidateCodeGenerator named <type>ValidateCodeGenerator
  2. Verify the generator is in a component-scanned package
  3. Confirm the bean name matches the convention exactly (lowercase type + 'ValidateCodeGenerator')
  4. If relying on the demo/ImageValidateCodeGenerator defaults, ensure SecurityCoreConfig is imported

Example fix

// before
// no generator for 'email' type -> throw
// after
@Component("emailValidateCodeGenerator")
public class EmailValidateCodeGenerator implements ValidateCodeGenerator {
    public ValidateCode generate(ServletWebRequest request) { /* ... */ }
}
Defensive patterns

Strategy: validation

Validate before calling

String genName = type.toLowerCase() + "ValidateCodeGenerator";
if (!applicationContext.containsBean(genName)) {
    throw new IllegalStateException("缺少bean: " + genName);
}

Try / catch

try { processor.validate(request); } catch (ValidateCodeException e) { model.addAttribute("codeError", e.getMessage()); return "login"; }

Prevention

When it happens

Trigger: 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.

Common situations: 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").

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10). Data as JSON: /api/errors/d86030dfd3121efe. Report an issue: GitHub.

Appendix: source

Thrown at paascloud-common/paascloud-security-core/src/main/java/com/paascloud/security/core/validate/code/impl/AbstractValidateCodeProcessor.java:75

	 * @throws Exception the exception
	 */
	@Override
	public void create(ServletWebRequest request) throws Exception {
		C validateCode = generate(request);
		save(request, validateCode);
		send(request, validateCode);
	}

	/**
	 * 生成校验码
	 */
	@SuppressWarnings("unchecked")
	private C generate(ServletWebRequest request) {
		String type = getValidateCodeType().toString().toLowerCase();
		String generatorName = type + ValidateCodeGenerator.class.getSimpleName();
		ValidateCodeGenerator validateCodeGenerator = validateCodeGenerators.get(generatorName);
		if (validateCodeGenerator == null) {
			throw new ValidateCodeException("验证码生成器" + generatorName + "不存在");
		}
		return (C) validateCodeGenerator.generate(request);
	}

	/**
	 * 保存校验码
	 */
	private void save(ServletWebRequest request, C validateCode) {
		ValidateCode code = new ValidateCode(validateCode.getCode(), validateCode.getExpireTime());
		validateCodeRepository.save(request, code, getValidateCodeType());
	}

	/**
	 * 发送校验码,由子类实现
	 *
	 * @param request      the request
	 * @param validateCode the validate code
	 *

View on GitHub (pinned to 781281a950)