ClassNotFoundException for HibernatePersistenceProvider

huangapple go评论77阅读模式
英文:

ClassNotFoundException for HibernatePersistenceProvider

问题

以下是翻译好的内容:

我有一个JSF项目,使用Java 7可以完美构建,但是当我尝试在Jboss应用服务器中部署WAR包时,出现了以下错误。

00:24:30.940 错误 [org.jboss.msc.service.fail] (MSC服务线程 1-16) MSC00001: 启动服务 jboss.deployment.unit."sample-1.0-SNAPSHOT.war".INSTALL 失败: org.jboss.msc.service.StartException 在服务 jboss.deployment.unit."sample-1.0-SNAPSHOT.war".INSTALL 中: 处理部署"sample-1.0-SNAPSHOT.war"的 INSTALL 阶段失败
	at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
	at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
	at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_80]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_80]
	at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_80]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011426: 无法部署应用程序打包的持久性提供程序 'org.hibernate.jpa.HibernatePersistenceProvider'
	at org.jboss.as.jpa.processor.PersistenceProviderProcessor.deploy(PersistenceProviderProcessor.java:91)
	at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
	... 5 more
Caused by: java.lang.ClassNotFoundException: 从 [Module "deployment.sample-1.0-SNAPSHOT.war:main" 来自服务模块加载器] 加载类 org.hibernate.jpa.HibernatePersistenceProvider 失败
	at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA]
	at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]
	at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]
	at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]
	at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]
	at org.jboss.as.jpa.processor.PersistenceProviderProcessor.deploy(PersistenceProviderProcessor.java:76)
	... 6 more

persistance.xml 文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="com.inmatic_JMS_war_1.0-SNAPSHOTPU" transaction-type="JTA">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>MySQLDS</jta-data-source>
    <class>com.rnavagamuwa.paypal.business.entity.PayPalPayment</class>
    <class>com.rnavagamuwa.catalogue.stock.business.entity.MaterialStockOrder</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
        <property name="hibernate.enable_lazy_load_no_trans" value="true"/>
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/db"/>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
        <property name="hibernate.connection.username" value="root" />
        <property name="hibernate.connection.password" value="password" />
    </properties>
  </persistence-unit>
</persistence>

在pom中包含了以下依赖项:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-c3p0</artifactId>
    <version>5.4.21.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.4.21.Final</version>
    <scope>provided</scope>
    <exclusions>
        <exclusion>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.hibernate.javax.persistence</groupId>
    <artifactId>hibernate-jpa-2.1-api</artifactId>
    <version>1.0.2.Final</version>
</dependency>
<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-web-api</artifactId>
    <version>8.0.1</version>
    <type>jar</type>
</dependency>

JBoss版本为 7.1.1 Final

我在这里做错了什么?

英文:

I have a JSF project which builds perfectly with java 7, but when I try to deploy the WAR in Jboss Application Server, I'm getting the bellow error.

00:24:30,940 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-16) MSC00001: Failed to start service jboss.deployment.unit.&quot;sample-1.0-SNAPSHOT.war&quot;.INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit.&quot;sample-1.0-SNAPSHOT.war&quot;.INSTALL: Failed to process phase INSTALL of deployment &quot;sample-1.0-SNAPSHOT.war&quot;
	at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
	at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
	at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_80]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_80]
	at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_80]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011426: Could not deploy application packaged persistence provider &#39;org.hibernate.jpa.HibernatePersistenceProvider&#39;
	at org.jboss.as.jpa.processor.PersistenceProviderProcessor.deploy(PersistenceProviderProcessor.java:91)
	at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
	... 5 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.jpa.HibernatePersistenceProvider from [Module &quot;deployment.sample-1.0-SNAPSHOT.war:main&quot; from Service Module Loader]
	at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA]
	at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]
	at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]
	at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]
	at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]
	at org.jboss.as.jpa.processor.PersistenceProviderProcessor.deploy(PersistenceProviderProcessor.java:76)
	... 6 more

The persistance.xml looks like bellow

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;persistence version=&quot;2.0&quot; xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd&quot;&gt;
  &lt;persistence-unit name=&quot;com.inmatic_JMS_war_1.0-SNAPSHOTPU&quot; transaction-type=&quot;JTA&quot;&gt;
    &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
    &lt;jta-data-source&gt;MySQLDS&lt;/jta-data-source&gt;
      &lt;class&gt;com.rnavagamuwa.paypal.business.entity.PayPalPayment&lt;/class&gt;
      &lt;class&gt;com.rnavagamuwa.catalogue.stock.business.entity.MaterialStockOrder&lt;/class&gt;
      &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
    &lt;properties&gt;
        &lt;property name=&quot;hibernate.show_sql&quot; value=&quot;true&quot;/&gt;
        &lt;property name=&quot;hibernate.format_sql&quot; value=&quot;true&quot;/&gt;
        &lt;property name=&quot;hibernate.enable_lazy_load_no_trans&quot; value=&quot;true&quot;/&gt;
        &lt;property name=&quot;hibernate.connection.url&quot; value=&quot;jdbc:mysql://localhost:3306/db&quot;/&gt;
        &lt;property name=&quot;hibernate.connection.driver_class&quot; value=&quot;com.mysql.jdbc.Driver&quot;/&gt;
        &lt;property name=&quot;hibernate.dialect&quot; value=&quot;org.hibernate.dialect.MySQLDialect&quot; /&gt;
        &lt;property name=&quot;hibernate.connection.username&quot; value=&quot;root&quot; /&gt;
        &lt;property name=&quot;hibernate.connection.password&quot; value=&quot;password&quot; /&gt;
    &lt;/properties&gt;
  &lt;/persistence-unit&gt;
&lt;/persistence&gt;

The bellow dependencies are included in the pom

        &lt;dependency&gt;
            &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
            &lt;artifactId&gt;hibernate-c3p0&lt;/artifactId&gt;
            &lt;version&gt;5.4.21.Final&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
            &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
            &lt;version&gt;5.4.21.Final&lt;/version&gt;
            &lt;scope&gt;provided&lt;/scope&gt;
            &lt;exclusions&gt;
                &lt;exclusion&gt;
                    &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
                    &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
                &lt;/exclusion&gt;
            &lt;/exclusions&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
            &lt;artifactId&gt;hibernate-jpa-2.1-api&lt;/artifactId&gt;
            &lt;version&gt;1.0.2.Final&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;javax&lt;/groupId&gt;
            &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
            &lt;version&gt;8.0.1&lt;/version&gt;
            &lt;type&gt;jar&lt;/type&gt;
        &lt;/dependency&gt;

The JBoss version is 7.1.1 Final

What am I doing wrong here?

答案1

得分: 0

问题在于JBoss模块中的Hibernate库与我的项目之间发生了冲突。当我使用JBoss的最新版本(WildFly 20)时,问题消失了。需要注意的是,我不得不将MySQL连接器jar文件复制到WildFly的部署目录中,并且在我的项目中添加了以下数据源配置。

<datasources xmlns="http://www.jboss.org/ironjacamar/schema">
    <datasource jndi-name="MySQLDS" pool-name="MySQLPool">
        <connection-url>jdbc:mysql://localhost:3306/db</connection-url>
        <driver>mysql-connector-java-8.0.21.jar</driver>
        <pool>
            <max-pool-size>30</max-pool-size>
        </pool>
        <security>
            <user-name>username</user-name>
            <password>password</password>
        </security>
    </datasource>
</datasources>
英文:

The issue here was the conflict between the Hibernate jars in JBoss modules and my project. When I use the JBoss latest one(WildFly 20), the issue went away. Note that I had to copy the MySQL connector jar into WildFly deployments dir and add the following datasource to my project.

&lt;datasources xmlns=&quot;http://www.jboss.org/ironjacamar/schema&quot;&gt;
    &lt;datasource jndi-name=&quot;MySQLDS&quot; pool-name=&quot;MySQLPool&quot;&gt;
        &lt;connection-url&gt;jdbc:mysql://localhost:3306/db&lt;/connection-url&gt;
        &lt;driver&gt;mysql-connector-java-8.0.21.jar&lt;/driver&gt;
        &lt;pool&gt;
            &lt;max-pool-size&gt;30&lt;/max-pool-size&gt;
        &lt;/pool&gt;
        &lt;security&gt;
            &lt;user-name&gt;username&lt;/user-name&gt;
            &lt;password&gt;password&lt;/password&gt;
        &lt;/security&gt;
    &lt;/datasource&gt;
&lt;/datasources&gt;

huangapple
  • 本文由 发表于 2020年9月13日 03:45:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/63864283.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定