3

I have a spring project in which i am using a validator like the following:

<beans:bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"  
            p:basenames="WEB-INF/i18n/messages,WEB-INF/i18n/application" 
            p:fallbackToSystemLocale="false" />         

<beans:bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
    <beans:property name="validationMessageSource" ref="messageSource" />
</beans:bean>

<annotation-driven validator="validator" />

<resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**" />

When i run the project i get the following BeanCreationException:

org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'validator' defined in ServletContext resource [/WEB-INF/spring/appServlet
/servlet-context.xml]: Error setting property values; nested exception is 
org.springframework.beans.PropertyBatchUpdateException; nested 
PropertyAccessExceptions (1) are:

PropertyAccessException 1: org.springframework.beans.MethodInvocationException: 
Property 'validationMessageSource' threw exception; nested exception is 
java.lang.NoClassDefFoundError: org/hibernate/validator/resourceloading/ResourceBundleLocator

Here is my snippet of POM:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
    <version>1.3.2.RELEASE</version>
</dependency>
<!-- Hibernate entity manager with JPA 2 support. -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.3.0.Beta2</version>
</dependency>

<!-- Hibernate’s implementation of JSR-303. -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>4.2.0.Final</version>
</dependency>

<!-- The JSR-303 Bean Validation API library. -->
<dependency>
   <groupId>javax.validation</groupId>
   <artifactId>validation-api</artifactId>
   <version>1.0.0.GA</version> 
</dependency>

Why i am getting this error?

Thanks

6 Answers 6

3
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-validation</artifactId>
</dependency>

Just use following dependency, it will fix your issue as this dependency provides basic validation from get go similar to hibernate.

Sign up to request clarification or add additional context in comments.

1 Comment

Based on the question, seems like they don't use the spring boot + starters
2

Your dependencies are OK. Based on the provided information the error should not appear.

So I suggest you to check your IDE and whether the hibernate-validator dependency is really on classpath. If you are using Eclipse with M2E, try to update your project:

  • Project (right click on project) > Maven > Update Project....

1 Comment

Actually i had hibernate-validator 5, then i downgraded to hibernate-validator 4. What i did i remove both the jars from the local repository and then just installed the hibernate-validator 4. Then the error gone. :)
2

This might be a broken backwards compatibility issue: https://jira.springsource.org/browse/SPR-10466

Comments

2

I had a similar problem using hibernate 5.2.10.Final and hibernate-validator 6.0.2.Final (that package version doesn't seem to be in sync with the others). Turns out, hibernate-validator's groupId was changed from org.hibernate to org.hibernate.validator. Once I made that change, the error went away, however I am using Dropwizard and noticed that there may be a version conflict somewhere, so that's something to keep an eye on.

Comments

0

I also had this exact same problem, tried all sorts of combinations of JAR versions, different bean definitions, even customised class implementations. Turns out, I just had to clean the project and restart Eclipse. Problem solved, and lesson learnt!

Comments

0

Check your dependency

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.2.8.Final</version>
</dependency>

Is must be at the same version of your other Hibernate dependencies.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.