2013-01-16 65 views
0

我有一個新的應用程序Jboss使用.war文件我是試圖連接到MySQL數據庫在啓動時(init方法), 我已經修改了獨立-sip.xml並添加我的司機如下: https://zorq.net/b/2011/07/12/adding-a-mysql-datasource-to-jboss-as-7/mss-2.0.0.FINAL-jboss-as-7.1.2.Final java.lang.ClassNotFoundException:com.mysql.jdbc.Driver

在啓動日誌中我可以看到驅動程序和數據源加載正確:

23:19:30,565 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) JBAS010404: **Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver** (version 5.1) 
23:19:30,748 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "mysql-connector-java-5.1.22-bin.jar" 
23:19:30,750 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) JBAS010400: **Bound data source [java:jboss/datasources/opencall]** 
23:19:30,933 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1) 
23:19:30,954 INFO [org.jboss.as.osgi] (MSC service thread 1-1) JBAS011907: Register module: Module "deployment.mysql-connector-java-5.1.22-bin.jar:main" from Service Module Loader 

但我看到:

23:18:50,959 ERROR [stderr] (MSC service thread 1-5) java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from [Module "deployment.opencall-2.1.0-SNAPSHOT.war:main" from Service Module Loader] 
23:18:50,959 ERROR [stderr] (MSC service thread 1-5) at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) 

之後,我看到:

23:18:51,700 INFO [org.jboss.as.server] (Controller Boot Thread) JBAS018559: Deployed "mysql-connector-java-5.1.22-bin.jar" 

我認爲問題是,加載MySQL驅動程序之前,我的應用程序正在啓動。但不知道如何強制我的應用程序在部署之前在啓動期間使用mysql驅動程序。這是我的代碼: 當我沒有使用Jboss運行它時,它工作正常,只有當我部署war文件失敗。

try { 

    Class.forName(dbClass).newInstance(); 

} catch (InstantiationException e) { 
    logger.error("InstantiationException() Exception"); 
    e.printStackTrace(); 
} catch (IllegalAccessException e) { 
    logger.error("IllegalAccessException() Exception"); 
    e.printStackTrace(); 
} 
     if (dbPassword.equals(null)) 
    dbPassword=""; 
    Connection dbConnection = DriverManager.getConnection (dbUrl,dbUserName,dbPassword); 
    dbConnection.close(); 

發現這一點: 這是一個類似的問題: http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

+0

林並添加到pom.xml,重新運行maven install並重新部署,但沒有運氣: javax.sql com.mysql.jdbc 5.1.22 系統 /Users/opencall/Documents/OpenSource/Development/Java/Mobicents/mss-2.0.0.FINAL-jboss-as-7.1.2 .Final/standalone/lib/mysql-connector-java-5.1.22-bin.jar spicyramen

回答

0
<!-- mysql dependencies --> 
    <dependency> 
    <groupId>mysql</groupId> 
    <artifactId>mysql-connector-java</artifactId> 
    <version>5.1.23</version> 
    </dependency> 

新增的對MySQL在我的Maven依賴(pom.xml的),然後使用maven安裝重新建立

相關問題