无法使用HIbernate在JBoss上加载所请求的类:com.mysql.jdbc.Driver [英] Could not load requested class : com.mysql.jdbc.Driver on JBoss using HIbernate

查看:75
本文介绍了无法使用HIbernate在JBoss上加载所请求的类:com.mysql.jdbc.Driver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在工作中设置一个EJB项目来学习Hibernate,到目前为止,我一直坚持这个错误。我尝试了几乎所有我在SO或其他地方找到的解决方案都无济于事。该项目有一个TimerBean,它调用另一个Bean的方法,使用Hibernate访问数据库并打印出一个存储值。我使用JPA从表中生成实体类,并为生成的实体类手动编写映射文件。以下是我项目中的相关文件:

hibernate.cfg.xml

 <?xml version ='1.0'encoding ='utf-8'?> 
<!DOCTYPE hibernate-configuration PUBLIC
- // Hibernate / Hibernate配置DTD 3.0 // EN
http://www.hibernate.org/dtd/hibernate-configuration -3.0.dtd>
< hibernate-configuration>
< session-factory>
<! - 数据库连接设置 - >
< property name =connection.driver_class> com.mysql.jdbc.Driver< / property>
< property name =connection.url> jdbc:mysql:// localhost:3306 / accountdb< / property>
< property name =connection.username> root< / property>
< property name =connection.password> pass< / property>

<! - Hibernate属性 - >
< property name =show_sql> true< / property>
< property name =dialect> org.hibernate.dialect.MySQLDialect< / property>
< property name =hbm2ddl.auto>更新< / property>

<! - 映射文件 - >
< mapping resource =com / gto / test / Account.hbm.xml/>
< / session-factory>
< / hibernate-configuration>

persistence.xml

 <?xml version =1.0encoding =UTF-8?> 
< persistence version =2.1xmlns =http://xmlns.jcp.org/xml/ns/persistencexmlns:xsi =http://www.w3.org/2001/XMLSchema-实例xsi:schemaLocation =http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd\">
< persistence-unit name =TestEJB3Project>
< provider> org.hibernate.ejb.HibernatePersistence< / provider>
< class> com.gto.test.Account< / class>
< class> com.gto.test.Accountaccesslog< / class>
< / persistence-unit>



AccountAccessBean.java

  package com.gto.test; 

import javax.ejb.LocalBean;
import javax.ejb.Stateless;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
导入org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

@Stateless(mappedName =AccountAccessBean)
@LocalBean
public class AccountAccessBean {
public void resigterAccountEvent(){

配置configuration = new Configuration()。configure();
ServiceRegistry registry = new StandardServiceRegistryBuilder()。applySettings(configuration.getProperties())。build();
SessionFactory sessionFactory = configuration.buildSessionFactory(registry);
Session session = sessionFactory.openSession();

session.beginTransaction();
Account accountEntity =(Account)session.get(Account.class,new Integer(1));
System.out.println(accountEntity.getId());
}
}

Account.hbm.xml

 <?xml version =1.0?> 
<!DOCTYPE hibernate-mapping PUBLIC
- // Hibernate / Hibernate映射DTD 3.0 // EN
http://www.hibernate.org/dtd/hibernate-mapping -3.0.dtd>
< hibernate-mapping package =com.gto.test>
< class name =Accounttable =account>
< id name =idcolumn =id>
< generator class =increment/>
< / id>
< property name =accessCountcolumn =accessCount/>
< / class>
< / hibernate-mapping>

服务器日志

  15:18:00,184 WARN [org.hibernate.orm.connections](EJB默认 -  1)HHH10001002:使用Hibernate内置连接池(不适合生产使用!)
15:18:00,184错误[org.jboss.as.ejb3](EJB默认值 - 1)WFLYEJB0020:调用计时器超时的错误:[id = e4f1edcd-d8cb-4f38-9a17-78df26ccc2ea timedObjectId = TestEJB3Project.TestEJB3Project。 TimerBean自动定时器?:真正持久性?:true timerService = org.jboss.as.ejb3.timerservice.TimerServiceImpl@15178ba initialExpiration = null intervalDuration(以毫秒为单位)= 0 nextExpiration = Wed Jul 27 15:18:30 IST 2016 timerState = IN_TIMEOUT info =每30秒调用一次AccountAccessBean]:javax.ejb.EJBException:org.hibernate.service.spi.ServiceException:无法创建请求的服务[org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:187)
at org.jboss.as.ejb 3.tx.TimerCMTTxInterceptor.handleExceptionInOurTx(TimerCMTTInterceptor.java:53)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:277)
at org.jboss.as。 ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:327)
位于org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239)
位于org.jboss.invocation。 InterceptorContext.proceed(InterceptorContext.java:340)
处org.jboss.invocation.InterceptorContext org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
。继续(InterceptorContext.java:340)
at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:100)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext。 java:340)
at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory $ 1.processInvocation(ShutDownInterceptorFactory.java:64)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
at org.jboss。 invocation.InterceptorContext.proceed(InterceptorContext.java:340)
位于org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:54)
位于org.jboss.invocation。 InterceptorContext.proceed(InterceptorContext.java:340)
在org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
在org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:
at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:636)
在org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)
。 jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
在org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)
在org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation( PrivilegedWithCombinerInterceptor.java:80)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ejb3.timerservice.TaleroidTask.invokeBeanMethod(CalendarTimerTask.java:64)$ b org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:99)
$ b at org.jboss.as.ejb3.timerservice.CalendarTimerTask.callTimeout(CalendarTimerTask.java:53)
at org.jboss.as.ejb3.timerservice.TimerTask.run(TimerTask.java:155)
at org.jboss.as.ejb3.timerservice.TimerServiceImpl $ Task $ 1.run(TimerServiceImpl.java:1214)
at org.wildfly.extension.requestcontroller.RequestController $ Queued任务$ 1.run(RequestController.java:497)
在java.util.concurrent.ThreadPoolExecutor.runWorker(未知源)
在java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知源)
在java.lang.Thread.run(未知源)
在org.jboss.threads.JBossThread.run(JBossThread.java:320)

引起:org.hibernate .service.spi.ServiceException:无法创建请求的服务[org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
在org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(Standa rdServiceRegistryImpl.java:94)
在org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
在org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java: 189)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete( MetadataBuildingProcess.java:111)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
at org.hibernate.boot.internal.MetadataBuilderImpl.build( MetadataBuilderImpl.java:418)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
at com.gto.test.AccountAccessBean.resigterAccountEvent(AccountAccessBean.java:44)
at com.gto.test.TimerBean.scheduledT imeout(TimerBean.java:29)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
在sun.reflect.NativeMethodAccessorImpl.invoke(来源不明)
在sun.reflect.DelegatingMethodAccessorImpl .invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
在org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
在org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:57)
在org.jboss。 as.ee.component.interceptors.UserInterceptorFactory $ 1.processInvocation(UserInterceptorFactory.java:61)
在org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
在org.jboss.invocation .InterceptorContext $ Invocation.proceed(InterceptorContext.java:437)
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsIntercepto r.java:82)
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:95)
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory $ 1 .processInvocation(UserInterceptorFactory.java:61)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:57 )
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory $ 1.processInvocation(UserInterceptorFactory.java:61)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext $ Invocation.proceed(InterceptorContext.java:437)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInv (org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext。
at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss .invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:52)
org.jboss.invocation .InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.c omponent.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.tx。 CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)
... 33 more

引起:org.hibernate.boot.registry.classloading.spi.ClassLoadingException:无法加载class [com .mysql.jdbc.Driver]
位于org.hibernate.engine.jdbc.connections.internal处的org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:229)
.DriverManagerConnectionProviderImpl.loadDriverIfPossible(DriverManagerConnectionProviderImpl.java:161)
位于org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator(DriverManagerConnectionProviderImpl.java:117)
位于org.hibernate.engine.jdbc .connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:73)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
在org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
在org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234)
... 80个月re

引起:java.lang.ClassNotFoundException:无法加载请求的类:com.mysql.jdbc.Driver
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl $ AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:217)$ b $在java.lang.ClassLoader.loadClass(未知源)
在java.lang.ClassLoader.loadClass(未知源)
在java.lang中.Class.forName0(本地方法)$ b $在java.lang.Class.forName(未知源)
在org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:226 )
... 91 more

这里是我的项目目录结构的一部分



任何帮助表示赞赏。我已经尝试了几乎所有可以在网上找到的解决方案,但我注意到它们主要针对简单的Java项目,而不适用于企业级项目。我也尝试使用JDBC驱动程序创建一个简单的连接来访问数据库,但这也不起作用。简单的Java项目中的连接工作得很好。提前致谢!

解决方案

我确实解决了这个问题,但我不确定这是否是正确的方式,问题实际上已经修复。我在META-INF目录中的项目中添加了 jboss-deployment-structure.xml 文件:

 < JBoss的部署-结构> 
< deployment>
<依赖关系>
< module name =javax.api/>
< module name =javax.transaction.api/>
< module name =javax.xml.rpc.api/>
< module name =javax.rmi.api/>
< module name =org.omg.api/>
< module name =configext/>
< /依赖关系>
< / deployment>



然后,在服务器安装root,在模块下/我添加了一个configext / module /文件夹,并将所有JAR文件复制到它中,并将 module.xml 文件添加到目录中:

 < module xmlns =urn:jboss:module:1.3name =configext> 
<依赖关系>
< module name =javax.api/>
< /依赖关系>
<资源>
< resource-root path =mysql-connector-java-5.1.39-bin.jar/>
< resource-root path =antlr-2.7.7.jar/>
< resource-root path =cdi-api-1.1-PFD.jar/>
< resource-root path =classmate-1.3.0.jar/>
< resource-root path =dom4j-1.6.1.jar/>
< resource-root path =el-api-2.2.jar/>
< resource-root path =geronimo-jta_1.1_spec-1.1.1.jar/>
< resource-root path =hibernate-commons-annotations-5.0.1.Final.jar/>
< resource-root path =hibernate-core-5.2.1.Final.jar/>
< resource-root path =hibernate-jpa-2.1-api-1.0.0.Final.jar/>
< resource-root path =jandex-2.0.0.Final.jar/>
< resource-root path =javassist-3.20.0-GA.jar/>
< resource-root path =javax.inject-1.jar/>
< resource-root path =jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar/>
< resource-root path =jboss-logging-3.3.0.Final.jar/>
< resource-root path =jsr250-api-1.0.jar/>
< /资源>



这些包放到服务器的全局类路径中。我可能完全错误,但这似乎工作。如果这不是一个永久性修复或不正确的做法,我仍然乐于接受建议。非常感谢!


I've been trying to set up an EJB project at work to learn Hibernate and so far I've been stuck with this error. I've tried almost all soltions I found on SO or elsewhere to no avail. The project has a TimerBean that invokes a methos from another Bean that accesses the database using Hibernate and prints out a stored value. I generated the entity classes from the tables using JPA and manually wrote a mapping file for the generated entity class. Here are the relevant files in my project:

hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>       
  <session-factory>
    <!-- Database connection settings -->
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property> 
    <property name="connection.url">jdbc:mysql://localhost:3306/accountdb</property>
    <property name="connection.username">root</property>
    <property name="connection.password">pass</property>

    <!-- Hibernate properties -->
    <property name="show_sql">true</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hbm2ddl.auto">update</property>

    <!-- Mapping Files -->
    <mapping resource="com/gto/test/Account.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="TestEJB3Project">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
  <class>com.gto.test.Account</class>
  <class>com.gto.test.Accountaccesslog</class>
</persistence-unit>

AccountAccessBean.java

package com.gto.test;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

@Stateless(mappedName = "AccountAccessBean")
@LocalBean
public class AccountAccessBean {
    public void resigterAccountEvent() {

        Configuration configuration = new Configuration().configure();
        ServiceRegistry registry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
        SessionFactory sessionFactory = configuration.buildSessionFactory(registry);
        Session session = sessionFactory.openSession();

        session.beginTransaction();
        Account accountEntity = (Account) session.get(Account.class, new Integer(1));
        System.out.println(accountEntity.getId());
    }
}

Account.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.gto.test">
    <class name="Account" table="account">
        <id name="id" column="id">
            <generator class="increment" />
        </id>
        <property name="accessCount" column="accessCount"/>
    </class>
</hibernate-mapping>

Server Log

15:18:00,184 WARN  [org.hibernate.orm.connections] (EJB default - 1)       HHH10001002: Using Hibernate built-in connection pool (not for production use!)
15:18:00,184 ERROR [org.jboss.as.ejb3] (EJB default - 1) WFLYEJB0020: Error invoking timeout for timer: [id=e4f1edcd-d8cb-4f38-9a17-78df26ccc2ea timedObjectId=TestEJB3Project.TestEJB3Project.TimerBean auto-timer?:true persistent?:true   timerService=org.jboss.as.ejb3.timerservice.TimerServiceImpl@15178ba initialExpiration=null intervalDuration(in milli sec)=0 nextExpiration=Wed Jul 27 15:18:30 IST 2016 timerState=IN_TIMEOUT info=Calls AccountAccessBean every 30 seconds]: javax.ejb.EJBException: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:187)
at org.jboss.as.ejb3.tx.TimerCMTTxInterceptor.handleExceptionInOurTx(TimerCMTTxInterceptor.java:53)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:277)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:327)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:100)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:54)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:636)
at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)
at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:99)
at org.jboss.as.ejb3.timerservice.CalendarTimerTask.invokeBeanMethod(CalendarTimerTask.java:64)
at org.jboss.as.ejb3.timerservice.CalendarTimerTask.callTimeout(CalendarTimerTask.java:53)
at org.jboss.as.ejb3.timerservice.TimerTask.run(TimerTask.java:155)
at org.jboss.as.ejb3.timerservice.TimerServiceImpl$Task$1.run(TimerServiceImpl.java:1214)
at org.wildfly.extension.requestcontroller.RequestController$QueuedTask$1.run(RequestController.java:497)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)

Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
at com.gto.test.AccountAccessBean.resigterAccountEvent(AccountAccessBean.java:44)
at com.gto.test.TimerBean.scheduledTimeout(TimerBean.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:57)
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:61)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82)
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:95)
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:61)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:57)
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:61)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:73)
at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:52)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)
... 33 more

Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [com.mysql.jdbc.Driver]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:229)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.loadDriverIfPossible(DriverManagerConnectionProviderImpl.java:161)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator(DriverManagerConnectionProviderImpl.java:117)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:73)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234)
... 80 more

Caused by: java.lang.ClassNotFoundException: Could not load requested class : com.mysql.jdbc.Driver
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:217)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:226)
... 91 more

Here's a snip of my project directory structure

Any help is appreciated. I've tried almost all solutions I could find online, but I noticed they were mostly for simple java projects and not for an enterprise one. I also tried creating a simple connection using the JDBC driver to access the DB but that didn't work either. Connections in a simple Java project are working just fine. Thanks in advance!

解决方案

I did fix the issue but I'm not sure if it's the right way to do it or the issue has been actually fixed. I added a jboss-deployment-structure.xml file to my project in the META-INF directory:

<jboss-deployment-structure>
<deployment>
    <dependencies>          
        <module name="javax.api" />
        <module name="javax.transaction.api" />
        <module name="javax.xml.rpc.api" />
        <module name="javax.rmi.api" />
        <module name="org.omg.api" />
        <module name="configext" />
    </dependencies>
</deployment>

Then, in the server installation root, under modules/ I added a configext/ module/folder and copied all my JAR files into it and added a module.xml file to the directory:

<module xmlns="urn:jboss:module:1.3" name="configext">
<dependencies>          
    <module name="javax.api" />
</dependencies>
<resources>
    <resource-root path="mysql-connector-java-5.1.39-bin.jar"/>
    <resource-root path="antlr-2.7.7.jar"/>
    <resource-root path="cdi-api-1.1-PFD.jar"/>
    <resource-root path="classmate-1.3.0.jar"/>
    <resource-root path="dom4j-1.6.1.jar"/>
    <resource-root path="el-api-2.2.jar"/>
    <resource-root path="geronimo-jta_1.1_spec-1.1.1.jar"/>
    <resource-root path="hibernate-commons-annotations-5.0.1.Final.jar"/>
    <resource-root path="hibernate-core-5.2.1.Final.jar"/>
    <resource-root path="hibernate-jpa-2.1-api-1.0.0.Final.jar"/>
    <resource-root path="jandex-2.0.0.Final.jar"/>
    <resource-root path="javassist-3.20.0-GA.jar"/>
    <resource-root path="javax.inject-1.jar"/>
    <resource-root path="jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar"/>
    <resource-root path="jboss-logging-3.3.0.Final.jar"/>
    <resource-root path="jsr250-api-1.0.jar"/>
</resources>    

I read somewhere that this adds these packages onto the server's global classpath. I might be entirely wrong but this seems to work. If this is not a permanent fix or the incorrect way to do things, I'm still open to suggestions. Thanks a bunch!

这篇关于无法使用HIbernate在JBoss上加载所请求的类:com.mysql.jdbc.Driver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆