Spring Boot. I have a service where the parameter is validated
@Override
public void registerUser(
@Valid RegisterDTO registerDTO
) {
The field that is validated is e. g.
@NotEmpty
@Pattern(regexp = "[a-zA-Z0-9_-]{6,36}")
private String username;
Then I set ExceptionHandler to pick up this exception
@ExceptionHandler(ConstraintViolationException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ValidationErrorDTO processValidationError(ConstraintViolationException ex) {
ValidationErrorDTO validationErrorDTO = new ValidationErrorDTO();
Set<ConstraintViolation<?>> set = ex.getConstraintViolations();
for (Iterator<ConstraintViolation<?>> iterator = set.iterator();iterator.hasNext(); ) {
ConstraintViolation<?> next = iterator.next();
validationErrorDTO.getFieldErrors()
.add(new ErrorFieldDTO(((PathImpl)next.getPropertyPath()).getLeafNode().getName(),
next.getMessage()));
}
return validationErrorDTO;
}
I have a validationMessages. properties file where I keep my bug messages
NotEmpty.registerDTO.username=This field is required.
Pattern.registerDTO.username=Please enter at least 6 characters(max. 36 characters). Only letters, numbers and special characters '_' and '-'.
However, the result of this operation appears to be https://zapodaj.net/d1a4f695e6a7d.png.html
Does not retrieve a local message from the. properties file.
How to set up for local messages to be downloaded from the properties file?