No validator could be found for constraint 'javax.validation.constraints.NotBlank' validating type 'java.lang.String'

Fede Jinich picture Fede Jinich · Oct 18, 2018 · Viewed 22.3k times · Source

I'm using Hibernate validator to validate my beans.

Actually I have this dependencies on my POM

    <!-- Hibernate validator - Bean validation API Implementation -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>6.0.11.Final</version>
    </dependency>

    <!-- Verify validation annotations usage at compile time -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-annotation-processor</artifactId>
        <version>6.0.11.Final</version>
    </dependency>

    <!-- Unified Expression Language - Spec -->
    <dependency>
        <groupId>javax.el</groupId>
        <artifactId>javax.el-api</artifactId>
        <version>3.0.1-b06</version>
    </dependency>

    <!-- Unified Expression Language - Implementation -->
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>javax.el</artifactId>
        <version>2.2.6</version>
    </dependency>

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

And this a pice of my bean

import org.hibernate.annotations.ColumnDefault;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;

public class Casa {

    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private Integer id;

    @Column(name="nomcaac") @NotBlank(message = "{casa.nomcaac.null}") @Size(min = 0, max = 300, message = "{casa.nomcaac.size}")
    private String nomcaac;

Now the problem comes when i try to validate my bean, i get this error message

No validator could be found for constraint 'javax.validation.constraints.NotBlank' validating type 'java.lang.String'. Check configuration for 'nomcaac'

I can't figure out whats my problem, I think I have the right dependencies according to this page.

Answer

Guillaume Smet picture Guillaume Smet · Oct 18, 2018

@NotBlank is new in Bean Validation 2.0 so I suspect you have an old Hibernate Validator version (e.g. 5.x) in your classpath somehow.

You should check your dependency tree with mvn dependency:tree (and your webapp looking for an old jar).

By the way, your javax.el dependencies are incorrect: please refer to https://github.com/hibernate/hibernate-validator/#using-hibernate-validator for the correct one.