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 package javax.validation.constraints does not exist

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 REST Validation Example

In Spring MVC, just annotate a @Valid on the @RequestBody to fire the validation process. Note For complete source code, please refer to this – Spring Boot Ajax example P.S Tested with Spring Boot 1.5.1.RELEASE (Spring 4.3.6.RELEASE) 1. JSR 303 Validation Add JSR303 annotations on a bean. package com.mkyong.model; import org.hibernate.validator.constraints.NotBlank; public class SearchCriteria { […]

Read more Spring REST API Validation

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 Spring Boot @ConfigurationProperties example

This tutorial shows you how to do form handling in Spring Web MVC application. Technologies and tools used: Java 11 Spring 5.2.22.RELEASE JSP JSTL 1.2 Embedded Jetty Server 9.4.45.v20220203 Servlet API 4.0.4 Bootstrap 5.2.0 (webjars) Hibernate Validator 6.2.5.Final HSQLDB 2.7.0 IntelliJ IDEA Maven 3.8.6 Spring Test 5.2.22.RELEASE Hamcrest 2.2 JUnit 5.9 Table of contents: 1. […]

Read more Spring MVC form handling example