Search code examples
springhibernatehibernate-validator

getting error java.lang.NoClassDefFoundError: org/hibernate/validator/resourceloading/ResourceBundleLocator


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


Solution

  • 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....