package javax.validation.constraints does not exist

Below is a Spring Boot application and validation bean API example. GlobalProperties.java import javax.validation.constraints.Max; import javax.validation.constraints.Min; import javax.validation.constraints.NotEmpty; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import org.springframework.validation.annotation.Validated; @Component @ConfigurationProperties @Validated public class GlobalProperties { //@Value("${thread-pool}") @Max(5) @Min(0) private int threadPool; Run the Spring Boot application and hits the following error: Terminal package javax.validation.constraints does not exist Solution – …

Read more

Spring REST Validation Example

In this article, we will enhance the previous Spring REST Hello World example, by adding bean validation and custom validator. Technologies used : Spring Boot 2.1.2.RELEASE Spring 5.1.4.RELEASE Maven 3 Java 8 1. Controller Review the previous REST Controller again : BookController.java package com.mkyong; import com.mkyong.error.BookNotFoundException; import com.mkyong.error.BookUnSupportedFieldPatchException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import …

Read more

Combine Spring validator and Hibernate validator

In this article, we will show you how to validate the submitted form values with Spring validator and Hibernate Validator (bean validation). Technologies used : Spring 4.1.6.RELEASE Hibernate Validator 5.1.3.Final 1. Hibernate Validator The Hibernate validator will be fired if @Valid is provided. import org.hibernate.validator.constraints.NotEmpty; public class User { @NotEmpty String name; //… } @RequestMapping(value …

Read more