nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.ConfigurationImpl

江枫思渺然 提交于 2019-12-19 11:27:52

问题


 public ModelAndView Details(@ModelAttribute("") @Validated App app, BindingResult result, @RequestParam(value="paramSessionAttr", required=false) String sessionAttr, @RequestParam("paramAction") @NotNull @NotEmpty String param_action){ ... }

When I implement @NotNull @NotEmpty annotation validator in getParam its cause error said :

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appController' defined in file [C:\apache-tomcat-8.0.29\wtpwebapps\Application Portal\WEB-INF\classes\com\controller\AppController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.controller.AppController]: Constructor threw exception; nested exception is java.lang.Error: Unresolved compilation problems: 
The type javax.validation.Payload cannot be resolved. It is indirectly referenced from required .class files
The import javax.validation cannot be resolved

Using hibernate-validator-5.2.2.jar Tomcat 8.0 spring-4.2.3.jar

When I Import javax.validator which is validation-api-1.1.0.jar [JSR-349] its cause this error,

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.ConfigurationImpl

When I remove @NotNull @NotEmpty and validation-api-1.1.0.final working fine.

When I import validation-api-1.1.0.final without @NotNull @NotEmpty I got this error

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.ConfigurationImpl

I tried download from other source and import validation-api-1.1.0.final I also got the same error as above.

I have found org.hibernate.validator.internal.engine.ConfigurationImpl in hibernate-validator-5.2.2-Final.jar

servlet Possible bean configuration missing something ?

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="
   http://www.springframework.org/schema/beans     
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd
   http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

   <context:component-scan base-package="com.controller" />

   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/jsp/" />
      <property name="suffix" value=".jsp" />
   </bean>

    <bean class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>/WEB/INF/messages</value>
            </list>
        </property>
        <property name="defaultEncoding" value="UTF-8" />
   </bean> 

    <!--<bean id="validator" class="org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean" />  -->


    <mvc:default-servlet-handler/>
    <mvc:resources mapping="/resources/**" location="/resources/" cache-period="31556926"/>
    <mvc:annotation-driven />
</beans>

Imported Library

  • hibernate-validator-5.2.2.Final.jar
  • hibernate-validator-annotation-processor-5.2.2.Final.jar
  • hibernate-validator-cdi-5.2.2.Final.jar
  • javax.el-api-3.0.0.jar
  • jboss-logging.jar
  • spring-context-4.2.3.RELEASE.jar
  • spring-beans-4.2.3.RELEASE.jar
  • validation-api-1.1.0.final.jar
  • classmate-1.3.1.jar
  • slf4j-jdk14-1.7.13.jar

REFERENCES

  • Exception in hibernate-validator. nested exception is java.lang.NoClassDefFoundError: ConfigurationImpl
  • Javax Validation
  • http://central.maven.org/maven2/org/hibernate/hibernate-validator/5.2.2.Final/hibernate-validator-5.2.2.Final.pom
  • http://docs.jboss.org/hibernate/validator/5.2/reference/en-US/pdf/hibernate_validator_reference.pdf

回答1:


Maybe lib conflict happens.

With my case:

jboss.common:jboss-common:jar:1.2.1.GA
org.jboss.logging:jboss-logging:jar:3.3.0.Final

exist together, but they have same package "org.jboss.logging".

Just exclusion one in pom.xml




回答2:


I guess some library is missing because I download library à la carte

you download from here as a package instead of you download à la carte

setup GUIDELINE http://hibernate.org/validator/documentation/getting-started/

Import and include library below in your project

  • classmate-1.1.0.jar
  • javax.el-2.2.4.jar
  • javax.el-api-2.2.4.jar
  • jboss-logging-3.2.1.Final.jar
  • validation-api-1.1.0.Final.jar
  • hibernate-validator-5.2.2.Final.jar
  • hibernate-validator-annotation-processor-5.2.2.Final.jar
  • hibernate-validator-cdi-5.2.2.Final.jar

Then your code should be working.




回答3:


I used sts to generate the spring project. I was getting the above error. After spending 2 days, I figured adjusting the version fix the problem.

In the parent section of pom.xml, I replaced 1.5.4 with 1.2.5

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.5.RELEASE</version>
  </parent>



回答4:


I was facing the same issue while working with JSR 303 bean validation I have added below two jar(along with validation-api-1.1.0.final.jar and hibernate-validator-5.0.1.final.jar) and the issue got resolved

1.classmate-0.8.0.jar 2.jboss-logging-3.1.0.ga.jar



来源:https://stackoverflow.com/questions/34764240/nested-exception-is-java-lang-noclassdeffounderror-could-not-initialize-class-o

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