Using Spring Boot 1.4 and Spring Data Rest/MVC I'm unable to get @Valid @RequestBody working. I have tried multiple versions of Hibernate Validator, declaring Validtor beans etc. No luck.
@BasePathAwareController
@RestController
public class TestRestController extends BaseController {
@PostMapping("/pojo/save")
public @ResponseBody ResponseEntity<?> upload(@Valid @RequestBody MyPojo pojo) {
// Code here calling a repository.save.
}
MyPojo contains various validation annotations i.e. @Digits, @NotNull, etc. I actually see the validator exception when the repostiory.save method is called but Spring is not attempting any validation on the pojo.
Here is the section of my POM including the spring dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
Any ideas would be appreciated. I've done a ton of searching and tried many different configurations without any luck.
Update
When attempting to save the entity to the database, that's when the validation errors occur. I receive the following error:
Caused by: javax.persistence.RollbackException: Error while committing the transaction
Caused by: javax.validation.ConstraintViolationException: Validation failed for classes
List of constraint violations:[
ConstraintViolationImpl{interpolatedMessage='numeric value out of bounds (<9 digits>.<3 digits> expected)...
@RequestBodyto@ModelAttributeif you are using Spring form in front end...show the front end code(how u calling this request) if possible - Prasanna Kumar H A