у вас импорт неправильный был вместо
import javax.validation.Valid;
@RestController
public class MainController
{
@PostMapping("/proxy/add")
public void saveProxy(@Valid @RequestBody ProxyDto dto) {
надо
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
@RestController
@RequestMapping("/proxy")
public class MainController
{
@RequestMapping(value = "add", method = RequestMethod.POST)
public Map<String, Object> addBook(@Validated @RequestBody ProxyDto dto ) {
....
и
import javax.validation.constraints.NotNull;
public class ProxyDto {
@NotNull(message = "idbn is missing")
@NotEmpty(message = "idbn is empty")
private String proxy;
в зависимости от версии фрамеворка скажкт типа
{
"timestamp": 1612029070201,
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.web.bind.MethodArgumentNotValidException",
"errors": [
{
"codes": [
"NotNull.book.isbn",
"NotNull.isbn",
"NotNull.java.lang.String",
"NotNull"
],
"arguments": [
{
"codes": [
"book.isbn",
"isbn"
],
"arguments": null,
"defaultMessage": "isbn",
"code": "isbn"
}
],
"defaultMessage": "idbn is missing",
"objectName": "book",
"field": "isbn",
"rejectedValue": null,
"bindingFailure": false,
"code": "NotNull"
},
{
"codes": [
"NotEmpty.book.isbn",
"NotEmpty.isbn",
"NotEmpty.java.lang.String",
"NotEmpty"
],
"arguments": [
{
"codes": [
"book.isbn",
"isbn"
],
"arguments": null,
"defaultMessage": "isbn",
"code": "isbn"
}
],
"defaultMessage": "idbn is empty",
"objectName": "book",
"field": "isbn",
"rejectedValue": null,
"bindingFailure": false,
"code": "NotEmpty"
}
],
"message": "Validation failed for object='book'. Error count: 2",
"path": "/book/add"
}