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

Spring Boot @ConfigurationProperties example

Spring Boot @ConfigurationProperties lets developers map or bind the entire external configuration values in .properties or .yml files to Java objects. Table of contents: 1. Access a single value using @Value 2. @ConfigurationProperties 3. Add JSR303 Validation 3.1 Add JSR 303 dependencies 3.2 @ConfigurationProperties and @Validated 4. Testing @ConfigurationProperties 5. Download Source Code 6. References …

Read more