java.lang.ClassNotFoundException:JBoss 7.1.1中的com.mysql.jdbc.Driver - 出了什么问题?

时间:2013-12-17 10:31:48

标签: mysql hibernate jdbc jboss

我有一个应用程序,它在context-common.xml中定义了一个数据源,详细信息从我的application.properties加载。

我尝试从jBoss https://community.jboss.org/wiki/DataSourceConfigurationInAS7

开始学习本教程

所以我在这个结构/ modules / com / mysql / main /中添加了mysql-connector-java-5.1.22,并添加了一个module.xml。它写着:

<resources>
    <resource-root path="mysql-connector-java-5.1.22.jar"/>
    <!-- Insert resources here -->
</resources>
<dependencies>
    <module name="javax.api"/>

</dependencies>

在我的standalone.xml中:

<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">

<connection-url>jdbc:mysql://localhost:3306/cab;DB_CLOSE_DELAY=-1</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
</datasource>
<drivers>
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>

我不明白我应该用jndi-name做什么?我是否需要它?我在使用JBoss 4时没有使用它。

此外,还有一些堆栈跟踪:

10:00:23,338 WARN  [org.hibernate.util.JDBCExceptionReporter] (MSC service thread 1-2) SQL Error: 0, SQLState: null
10:00:23,342 ERROR [org.hibernate.util.JDBCExceptionReporter] (MSC service thread 1-2) Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
10:00:23,347 WARN  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-2) Could not obtain connection metadata: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136) [commons-dbcp-1.2.2.jar:1.2.2]
    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) [commons-dbcp-1.2.2.jar:1.2.2]
    at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:83) [spring-orm-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84) [hibernate-3.2.7.ga.jar:3.2.7.ga]
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2090) [hibernate-3.2.7.ga.jar:3.2.7.ga]
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2086) [hibernate-3.2.7.ga.jar:3.2.7.ga]
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1311) [hibernate-3.2.7.ga.jar:3.2.7.ga]
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867) [hibernate-annotations-3.4.0.GA.jar:3.2.7.ga]
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:863) [spring-orm-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:782) [spring-orm-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188) [spring-orm-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:610) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) [spring-context-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) [spring-context-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) [spring-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) [spring-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_20]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_20]
    at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_20]
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from [Module "deployment.cab-1.0-SNAPSHOT.war:main" from Service Module Loader]

1 个答案:

答案 0 :(得分:1)

如果我理解正确,那么您的应用程序(DBCP)正在提供连接池机制。你似乎也在使用Spring自己发布Hibernate。您还提到您正在从属性文件中加载连接详细信息(也可以从您的war文件中加载)。如果这是正确的,那么您不需要对AS执行任何操作,您也可以将MySQL驱动程序与您的应用程序一起发送。

但真正的问题似乎是为什么你要运送AS已经提供的很多东西。虽然这似乎是2000年代中期的默认选择,但现代应用程序不应捆绑连接池(由AS本身提供),或Hibernate(也由AS通过JPA提供)或Spring Beans(大多数这些功能可以很容易地被CDI取代。