Trouble starting Hibernate Validator due to Bean Validation API

纵然是瞬间 提交于 2019-11-28 09:45:17

Try adding this dependency to your pom.xml

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>1.0.0.GA</version>
</dependency>

If not consider using hibernate-validator4.2.0.Final I have that one in my config and it is working fine.

For me, the 1.1.0.Final version javax.validation.validation-api had worked. Because, the javax.validation.spi.ConfigurationState interface of 1.1.0.Final has getParameterNameProvider method, which was absent in 1.0.0.GA.

I added the below dependency in pom.xml

<dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.1.0.Final</version>
           <scope>test</scope>
</dependency>

in my case i just deleted the hibernate-validator and it worked .(i also had a combo of both validation api and hibernate-validator and tried everything) or you can go to your maven repository-->org and then delete the hibernate folder and rebuild your project again.. hope it helps..

I thought it would be useful to explain what is going on here.

Hibernate is calling ConfigurationState.getParameterNameProvider:

ValidatorFactoryImpl.java:

public ValidatorFactoryImpl(ConfigurationState configurationState) {
   ...
   configurationState.getParameterNameProvider()
   ...
}

You can find the documentation of getParameterNameProvider:

getParameterNameProvider

ParameterNameProvider getParameterNameProvider()

Returns the parameter name provider for this configuration.

Returns:

parameter name provider instance or null if not defined

Since:

1.1

So what's the problem? The problem is that the method didn't always exist. It was added at some point in the future.

And the rule when creating interfaces is that they are set in concrete: you shall not change an interface ever. Instead the JavaX validator changed the ConfigurationState interface, and added a few new methods over the years.

The java validation code is passing the Hiberate an outdated ConfiguationState interface; one that doesn't implement the required interfaces.

You need to ensure that javax.validation.Validation.buildDefaultValidatorFactory is updated to to support version 1.1.

Shweta Tiwari

Removing this jar javax.validation:validation-api:1.1.0.Final solved my problem.

Make sure you have only one validation jar. If we have two jars then they may conflict resulting in error.

I had the problem again. Thats how I've fixed that:

1-Exclude spring.validator from the 'web' dependency:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate.validator</groupId>
                <artifactId>hibernate-validator</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

2-After insert the dependecy with a previous version:

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

Go to the dependecies project and delete, hibernate.validator, and reinstall that in the most recent version. It has solved the problem for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!