5.4 Validation Advice

Validation advice is one of the most common advice types you are likely to want to incorporate into your application.

Validation advice is built on Bean Validation JSR 380.

JSR 380 is a specification of the Java API for bean validation which ensures that the properties of a bean meet specific criteria, using javax.validation annotations such as @NotNull, @Min, and @Max.

Micronaut provides native support for the javax.validation annotations with the micronaut-validation dependency:

  1. implementation("io.micronaut:micronaut-validation")
  1. <dependency>
  2. <groupId>io.micronaut</groupId>
  3. <artifactId>micronaut-validation</artifactId>
  4. </dependency>

Or full JSR 380 compliance with the micronaut-hibernate-validator dependency:

  1. implementation("io.micronaut:micronaut-hibernate-validator")
  1. <dependency>
  2. <groupId>io.micronaut</groupId>
  3. <artifactId>micronaut-hibernate-validator</artifactId>
  4. </dependency>

See the section on Bean Validation for more information on how to apply validation rules to your bean classes.