Add validation module: Bean Validation on Spring Boot 4.2.0 with Hibernate Validator 9.1.6, built-in and custom constraints, groups, method validation, ProblemDetail errors, message i18n, JPA integration and tests, with real transcripts

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b4RzcCS5JCAgcxLz7T
This commit is contained in:
Claude
2026-12-05 16:18:03 +05:30
parent a95f042051
commit 417903fbc2
78 changed files with 2279 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
# validation
Companion code for [Bean Validation in Spring Boot 4](https://ankurm.com/custom-validation-in-spring-boot-beyond-the-basics/) on ankurm.com.
Built and run with Spring Boot 4.2.0, Spring Framework 7.1.0, Hibernate Validator 9.1.6.Final,
Jakarta Validation 3.1.1, Hibernate ORM 7.4.15.Final and JDK 25.0.5.1.
```bash
mvn test # 23 tests, which also rewrite most of output/
./scripts/run-all.sh # everything in output/, including the plain-Java, javac and Boot 4.1.3 runs
mvn spring-boot:run # the endpoints in web/ on :8080
```
`app.problem-advice=false` switches the `@RestControllerAdvice` off so you can see the defaults.
## Where things are
| Topic | Source | Output |
|---|---|---|
| Versions on the classpath | `pom.xml` | `00` |
| Built-in constraints, null handling, mistakes | `ConstraintCheatSheetTest` | `01`, `02` |
| Custom constraints, injection into validators | `constraint/`, `CustomConstraintTest` | `03` |
| Cascading, records, container elements | `model/`, `CustomConstraintTest` | `04`, `19`, `21` |
| Cross-field constraints | `DateRange*`, `PasswordsMatch*` | `05` |
| Groups, sequences, group conversion | `Groups`, `GroupsTest` | `06`, `12` |
| Method validation on services | `service/`, `MethodValidation*Test` | `07`, `08` |
| HTTP defaults and ProblemDetail | `web/`, `WebDefaultsTest`, `ProblemAdviceTest` | `09`, `10`, `11`, `22` |
| The `BindingResult` + `toMap` pitfalls | `BindingResultController` | `13` |
| Message sources and i18n, template safety | `messages*.properties`, `MessagesTest`, `ElInjectionTest` | `14`, `15`, `16` |
| Hibernate ORM integration | `jpa/`, `JpaIntegrationTest` | `17` |
| Testing | `ValidationSliceTest`, `DateRangeValidatorUnitTest`, `MockMvcEmptyBodyTest` | `18` |
| Hibernate Validator without Spring | `examples/plain-java/` | `20` |
The older [`custom-validation`](../custom-validation) module (Boot 4.1.1) stays as it was.