Validators do not work with Spring and TomEE without Maven or Grade.
I created an elementary project. When I enter incorrect data, the validator simply does nothing (no error, no log, nothing neite).
Nothing valid. It does not validate the parameters of the ret services. It does not validate on the created DTO. I tried in many ways.
I'm going crazy help me, please.
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@NotNull
public class PersonaDTO {
@Min(0)
@Max(270)
private int eta;
@Pattern(regexp = "[A-Z]+[a-z][a-z]+")
private String Cognome;
@Pattern(regexp = "[A-Z]+[a-z][a-z]+")
private String Nome;
@Max(240)
@Min(80)
private int altezza;
public PersonaDTO() {
}
public PersonaDTO( String cognome, String nome,int eta, int altezza) {
this.eta = eta;
Cognome = cognome;
Nome = nome;
this.altezza = altezza;
}
public String getCognome() {
return Cognome;
}
public void setCognome(String cognome) {
Cognome = cognome;
}
public String getNome() {
return Nome;
}
public void setNome(String nome) {
Nome = nome;
}
public int getAltezza() {
return altezza;
}
public void setAltezza(int altezza) {
this.altezza = altezza;
}
public int getEta() {
return eta;
}
public void setEta(int eta) {
this.eta = eta;
}
}
package it.paolo.spring.rest;
@RestController
@Validated
public class RestSpring {
@RequestMapping(value = "/crea/{cogome}/{nome}/{eta}/{altezza}",
produces = "application/json"
)
@Validated @Valid
public PersonaDTO creaPersona(
@PathVariable("cogome") @Pattern(regexp = "[A-Z]+[a-z][a-z]+") @Valid String strCognome,
@PathVariable("nome") @Valid @Pattern(regexp = "[A-Z]+[a-z][a-z]+") String strNome,
@PathVariable("eta") int intEta,
@PathVariable("altezza") int intAletezza
) {
PersonaDTO persona=new PersonaDTO(strCognome,strNome,intEta,intAletezza);
return persona;
}
}