Why can't I use the @NotEmpty
annotation to perform validation?
This is my code:
package mx.com.gm.domain;
import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.Email;
import lombok.Data;
@Data
@Entity
@Table(name = "persona")
public class Persona implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idPersona;
@NotEmpty
private String nombre;
@NotEmpty
private String apellido;
@NotEmpty
@Email
private String email;
@NotEmpty
private String telefono;
}
I'm trying to import javax.validation.constraints.NotEmpty
, but it doesn't show up in Apache NetBeans.
I found the answer. It's because the dependency is not included in the web starter dependencies. You need to add it manually in your pom.xml file:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>