2

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

Neuron
  • 5,141
  • 5
  • 38
  • 59
Basit
  • 8,426
  • 46
  • 116
  • 196

6 Answers6

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....
Pavel Horal
  • 17,782
  • 3
  • 65
  • 89
  • 1
    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. :) – Basit Jun 13 '13 at 08:26
2

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

Jaroslav Záruba
  • 4,694
  • 5
  • 39
  • 58
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.

Brooks
  • 7,099
  • 6
  • 51
  • 82
2
<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.

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!

khriskooper
  • 767
  • 8
  • 18
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.

Neuron
  • 5,141
  • 5
  • 38
  • 59
José Mendes
  • 950
  • 2
  • 14
  • 30