嵌套异常是java.lang.NoClassDefFoundError:无法初始化类org.hibernate.validator.internal.engine.ConfigurationImpl

时间:2016-01-13 10:29:08

标签: spring-mvc servlets hibernate-validator spring-validator

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

当我在getParam中实现@NotNull @NotEmpty注释验证器时,其原因错误说:

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

使用hibernate-validator-5.2.2.jar Tomcat 8.0 spring-4.2.3.jar

当我导入validation-api-1.1.0.jar [JSR-349]的javax.validator导致此错误时,

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

当我删除@NotNull @NotEmptyvalidation-api-1.1.0.final正常工作时。

当我导入validation-api-1.1.0.final而没有@NotNull @NotEmpty时,我收到了此错误

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

我尝试从其他来源下载并导入validation-api-1.1.0.final我也遇到了与上面相同的错误。

我在org.hibernate.validator.internal.engine.ConfigurationImpl

中找到了hibernate-validator-5.2.2-Final.jar

servlet 可能的bean配置丢失了什么?

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

导入的库

  • 冬眠验证器-5.2.2.Final.jar
  • 冬眠验证器的注释处理器的5.2.2.Final.jar
  • 冬眠-验证-CDI-5.2.2.Final.jar
  • javax.el-API-3.0.0.jar
  • 的JBoss-logging.jar
  • 弹簧上下文4.2.3.RELEASE.jar
  • 弹簧豆-4.2.3.RELEASE.jar
  • 验证-API-1.1.0.final.jar
  • 同学-1.3.1.jar
  • SLF4J-jdk14-1.7.13.jar

参考

4 个答案:

答案 0 :(得分:3)

可能发生了lib冲突。

以我的情况:

jboss.common:JBoss的共用:罐:1.2.1.GA
org.jboss.logging:JBoss的日志记录:罐:3.3.0.Final

一起存在,但他们有相同的包&#34; org.jboss.logging&#34;。

在pom.xml中排除一个

答案 1 :(得分:1)

我想有些库遗失了,因为我下载了库à la carte

您从here下载而不是下载à la carte

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

在项目中导入并包含以下库

  • 同学-1.1.0.jar
  • javax.el-2.2.4.jar
  • javax.el-API-2.2.4.jar
  • 的JBoss-测井3.2.1.Final.jar
  • 验证-API-1.1.0.Final.jar
  • 冬眠验证器-5.2.2.Final.jar
  • 冬眠验证器的注释处理器的5.2.2.Final.jar
  • 冬眠-验证-CDI-5.2.2.Final.jar

然后你的代码应该正常工作。

答案 2 :(得分:0)

我使用sts生成spring项目。我收到了上述错误。花了2天后,我想调整版本修复问题。

在pom.xml的父节中,我用1.5.5替换了1.5.4

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

答案 3 :(得分:0)

我在使用JSR 303 bean验证时遇到了同样的问题我在下面添加了两个jar(以及 validation-api-1.1.0.final.jar hibernate-validator -5.0.1.final.jar )问题得到解决

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