Hibernate 5.1.2 java.lang.NoClassDefFoundError:org / hibernate / boot / spi / SessionFactoryOptions

时间:2017-11-02 07:03:13

标签: hibernate classpath

我最近从Hibernate 4.3.10升级到5.2.12,当我尝试使用java 8在wildfly 9上部署应用程序时,我得到以下错误。

这是我的相关pom.xml代码段。

       <properties>
            <org.hibernate.version>5.2.12.Final</org.hibernate.version>
        </properties>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${org.hibernate.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${org.hibernate.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-ehcache</artifactId>
            <version>${org.hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-envers</artifactId>
            <version>${org.hibernate.version}</version>
        </dependency>

这是堆栈跟踪。

  

14:45:49,300 ERROR [org.jboss.msc.service.fail](ServerService线程池 - 17)MSC000001:无法启动服务   。jboss.persistenceunit “your.war#yourdb”:   服务中的org.jboss.msc.service.StartException   。jboss.persistenceunit “your.war#yourdb”:   java.lang.NoClassDefFoundError:   组织/休眠/启动/ SPI / SessionFactoryOptions         at org.jboss.as.jpa.service.PersistenceUnitServiceImpl $ 1 $ 1.run(PersistenceUnitServiceImpl.java:172)         在org.jboss.as.jpa.service.PersistenceUnitServiceImpl $ 1 $ 1.run(PersistenceUnitServiceImpl.java:117)         在org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:665)         在org.jboss.as.jpa.service.PersistenceUnitServiceImpl $ 1.run(PersistenceUnitServiceImpl.java:182)         在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)         at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)         在java.lang.Thread.run(Thread.java:745)         在org.jboss.threads.JBossThread.run(JBossThread.java:320)       引起:java.lang.NoClassDefFoundError:org / hibernate / boot / spi / SessionFactoryOptions         at java.lang.Class.getDeclaredMethods0(Native Method)         at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)         at java.lang.Class.privateGetPublicMethods(Class.java:2902)         在java.lang.Class.getMethods(Class.java:1615)         在org.hibernate.service.internal.AbstractServiceRegistryImpl.applyInjections(AbstractServiceRegistryImpl.java:278)         at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:269)         在org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:231)         在org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)         在org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:295)         在org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2444)         在org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2440)         在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)         在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.perform(EntityManagerFactoryBuilderImpl.java:857)         在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.perform(EntityManagerFactoryBuilderImpl.java:850)         at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)         在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)         在org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)         在org.jboss.as.jpa.service.PersistenceUnitServiceImpl $ 1 $ 1.run(PersistenceUnitServiceImpl.java:154)         ......还有7个       引起:[模块的java.lang.ClassNotFoundException:org.hibernate.boot.spi.SessionFactoryOptions   来自Service Module Loader的“deployment.your.war:main”         在org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)         at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)         在org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)         在org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)         在org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)

知道我的环境可能出现什么问题吗?

2 个答案:

答案 0 :(得分:0)

理想情况下,如果类路径上有不同的hibernate版本,就会发生这种情况。

答案 1 :(得分:0)

Wildfly有自己的Hibernate模块。您可以尝试使用exclusions排除它。

从此处使用排除项的示例 https://docs.jboss.org/hibernate/orm/5.2/topical/html_single/wildfly/Wildfly.html

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
    <deployment>
        <exclusions>
            <module name="org.javassist" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>