A Spring Boot 2 application that demonstrates how to customize the Hibernate Validator.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gradle/wrapper
src
.gitignore
LICENSE
README.md
build.gradle
gradlew
gradlew.bat
settings.gradle

README.md

validator-example

A Spring Boot 2 application that demonstrates how to customize the Hibernate Validator.

Specifically, this example configures a ClockProvider, and sets the hibernate.validator.temporal_validation_tolerance global property.

This allows for a margin of error, due to out of sync clocks for example, when validating temporal constraints such as:

javax.validation.constraints.Past
javax.validation.constraints.PastOrPresent
javax.validation.constraints.Future
javax.validation.constraints.FutureOrPresent

Running the tests

This example also demonstrates how to mock a ClockProvider during unit testing. Use the following command line to execute the tests:

./gradlew clean test 

References

  1. Hibernate Validator: 9.2.5. ClockProvider and temporal validation tolerance

  2. Spring Framework Reference: Configuring a Bean Validation Provider

  3. Spring Framework LocalValidatorFactoryBean Javadoc