How to manually trigger Spring validation?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In Spring MVC, validation often happens automatically when a controller parameter is annotated with @Valid or @Validated. But outside that request-binding flow, you may need to trigger validation yourself from a service, batch job, scheduled task, or custom workflow.
Spring supports this cleanly. The main question is whether you want Bean Validation through jakarta.validation.Validator or Spring's own Validator interface.
Manual Validation with Bean Validation
If your object uses annotations such as @NotBlank, @Email, or @Min, inject a Bean Validation Validator and call validate().
This is the most common manual-validation approach in Spring Boot applications.
Using Spring's Validator with Errors
If you have a custom Spring Validator, call it directly with a BindingResult implementation.
This style is useful when validation logic is custom and not expressed as bean annotations.
When Manual Validation Makes Sense
Manual validation is useful when the object is not being created by Spring MVC request binding. Typical examples include:
- messages read from a queue
- rows imported from a CSV file
- intermediate objects created inside a service
- validation before calling a downstream system
In those cases, relying on @Valid alone is not enough because no controller method is triggering the validation step for you.
Validation Groups and Reuse
Manual validation also gives you precise control over validation groups.
That is helpful when the same DTO has different rules for create versus update operations.
The broader design rule is simple: validation should live close to the boundary where incorrect data first becomes a problem. Sometimes that boundary is the controller. Sometimes it is a service or batch processor instead.
Common Pitfalls
- Assuming
@Validruns automatically everywhere. It only runs where Spring is actually managing the validation trigger. - Throwing away detailed violation information too early instead of mapping it into a useful error response.
- Mixing Bean Validation annotations and a custom Spring
Validatorwithout being clear about which one owns the rules. - Creating validation logic in controllers only, then forgetting to validate objects created elsewhere in the application.
- Manually validating but ignoring validation groups when different workflows need different constraints.
Summary
- Manual Spring validation is straightforward once you choose the right validator type.
- Use
jakarta.validation.Validatorfor annotation-based Bean Validation. - Use Spring's
ValidatorplusErrorsfor custom validation logic. - Manual validation is especially useful outside controller request binding.
- The goal is not just to "run validation," but to run it at the right application boundary.

