HV000030: No Validator could be found for Constraint 'javax.validation.constraints.Email' validating type 'java.lang.String'

Asked

Viewed 1,505 times

1

I’m in a class AdministradorDTO and added some validators to it I found a tutorial on the Internet and I followed the same way in my case it gives this error in the email, before it gave in String too. But then I switched @NotEmpty for @NotNull and it worked.

DTO

package com.dogwalk.dogwalk.dto;

import com.dogwalk.dogwalk.entity.Administrador;
import java.io.Serializable;
import java.util.Date;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;

/**
 *
 * @author andre
 */
public class AdministradorDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer id;
    @NotNull(message = "Preencha o campo Nome")
    private String nome;
    @NotNull(message = "Preencha o campo E-Mail")
    @Email(message = "Email inválido")
    private String email;
    private String senha;
    @NotNull(message = "Preencha o campo Adminstrador Master")
    private boolean master;
    private Date dtGravacao;
    private String userGravacao;

    public AdministradorDTO() {
    }

    public AdministradorDTO(Administrador administrador) {
        this.id = administrador.getId();
        this.nome = administrador.getNome();
        this.email = administrador.getEmail();
        this.master = administrador.getMaster();
        this.dtGravacao = administrador.getDtGravacao();
        this.userGravacao = administrador.getUserGravacao();
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public boolean isMaster() {
        return master;
    }

    public void setMaster(boolean master) {
        this.master = master;
    }

    public Date getDtGravacao() {
        return dtGravacao;
    }

    public void setDtGravacao(Date dtGravacao) {
        this.dtGravacao = dtGravacao;
    }

    public String getUserGravacao() {
        return userGravacao;
    }

    public void setUserGravacao(String userGravacao) {
        this.userGravacao = userGravacao;
    }

    public String getSenha() {
        return senha;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }
}

POM

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.dogwalk</groupId>
    <artifactId>dogwalk</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    <name>dogwalk</name>
    <description>Projeto Dog Walk</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!--        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>-->
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.1.1</version>
        </dependency>

        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.0.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>6.0.2.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator-annotation-processor</artifactId>
            <version>6.0.2.Final</version>
        </dependency>

        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>javax.el</artifactId>
            <version>2.2.6</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Does anyone know how I can fix this?

1 answer

2

How do you own the hibernate-validator in his pom.xml, change the annotation of:

javax.validation.constraints.Email

To:

org.hibernate.validator.constraints.Email

This way Hibernate will provide the appropriate validator that is registered in the application.

  • It worked, thank you! But it has happened that the Email class of this package is deprecated!

  • 1

    Interesting! In fact it was depreciated in favor of the JSR380 as described here, you could try updating your version of validation-api for version 2.0.1.Final and test by returning import to javax.validation.constraints.Email?

  • I updated the version and came back with import... Then the same error appeared again... Very strange...

  • 1

    Use the Hibernate for now, I’ll check later

Browser other questions tagged

You are not signed in. Login or sign up in order to post.