Files
spring-boot-demo/validation/README.md
T

35 lines
1.9 KiB
Markdown

# 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.