Reputation: 33
I follow a spring boot tutorial and I can't solve this problem because the tutorial is not detailed enough
package com.example.user;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;
public class User {
private Integer id;
@Size(min=2, message="Name should have atleast 2 characters")
private String name;
private Date birthDate;
protected User() {
}
public User(Integer id, String name, Date birthDate) {
super();
this.id = id;
this.name = name;
this.birthDate = birthDate;
}
//getters and setters
}
@PostMapping("/users")
public ResponseEntity<Object> createUser(@Valid @RequestBody User user) {
User savedUser = service.save(user);
URI location = ServletUriComponentsBuilder
.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(savedUser.getId()).toUri();
return ResponseEntity.created(location).build();
}
Upvotes: 0
Views: 29
Reputation: 33
I solve the problem :
The hibernate validator dependacy was missed so I add it to the POM and everything works fine
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.12.Final</version>
</dependency>
Upvotes: 1