创建名称为' org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean#0

时间:2016-03-14 11:23:56

标签: java hibernate

我是hibernate的新手,并不太确定我的应用程序有什么问题。 所以我有这两个模块:核心和网站。

  • 模块核心具有所有实体,daos和所有数据库工作。所有DAO都继承了AbstractDAO。
  • 模块网站完成所有前端工作,如jsps,mvc控制器......它是一个支持spring框架的maven模块。

我试图使用ehcache工厂实现二级缓存。但是我收到了这个错误:

  

org.springframework.beans.factory.BeanCreationException:创建名称为' org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean#0':init方法的调用失败;嵌套异常是java.lang.NoClassDefFoundError:无法初始化类org.hibernate.validator.internal.engine.ConfigurationImpl       org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)       org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)       org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)       org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:302)       org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)       org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)       org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)       org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:725)       org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)       org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)       org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663)       org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:629)       org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:677)       org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:548)       org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489)       org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)       javax.servlet.GenericServlet.init(GenericServlet.java:158)       org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)       org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)       org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)       org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)       org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)       org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:668)       org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.doRun(AprEndpoint.java:2503)       org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.run(AprEndpoint.java:2492)       java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)       java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)       org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)       java.lang.Thread.run(Thread.java:745)

当我添加logback-classic.jar时出现错误,但如果我删除它,我会收到另一个错误。

  

org.springframework.web.util.NestedServletException:处理程序处理失败;嵌套异常是java.lang.NoClassDefFoundError:ch / qos / logback / classic / selector / ContextSelector       在org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1287)       在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961)       在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)       在com.before90.website.action.application.ControllerServlet.doService(ControllerServlet.java:28)       在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)       在org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:622)

我不知道错误出现的原因。它表明存在一个spring框架错误,其中spring未在模块Core中实现(所有DAO都在其中)。任何建议将不胜感激。 感谢

5 个答案:

答案 0 :(得分:4)

如果您使用的是hibernate-validator,就我而言,我仅添加了以下一个依赖项:(因为javax.xml.bind在Java 9及更高版本中默认情况下在类路径中不可用,请参考{{ 3}} )

https://docs.oracle.com/javase/9/docs/api/java.xml.bind-summary.html

答案 1 :(得分:3)

我不认为你可以使用fixtures(对于Hibernate 5)和Hibernate 4.尝试使用hibernate-validator 5.2.2

您班级路径中有两个hibernate-validator 4.2.0.Final个罐子!

尝试使用Maven或Gradle构建来获得有效的依赖。

答案 2 :(得分:2)

您需要所有都需要依赖

    <!-- JSR 303 Dependencies -->

    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.1.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.4.3.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-annotation-processor</artifactId>
        <version>5.4.3.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-cdi</artifactId>
        <version>5.4.3.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.logging</groupId>
        <artifactId>jboss-logging</artifactId>
        <version>3.3.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.el</artifactId>
        <version>3.0.1-b08</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml</groupId>
        <artifactId>classmate</artifactId>
        <version>1.3.1</version>
    </dependency>

答案 3 :(得分:0)

您无需删除logback-classic.jar, 相反,根本原因似乎是org.hibernate.validator.internal.engine.ConfigurationImpl的缺失定义。 根据Google,您需要添加http://mvnrepository.com/artifact/org.hibernate/hibernate-validator 如果它是一个maven项目,那么你的pom依赖项中的下面的配置将使你的工作顺利进行

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.2.4.Final</version>

答案 4 :(得分:-4)

问题出在WAR上。