【发布时间】:2018-07-07 03:16:24
【问题描述】:
我在 IBM WebSphere Application Server Liberty Profile 上部署了一个 spring mvc 应用程序,该应用程序应该访问本地托管的 mysql 数据库服务器。我在 sever.xml 文件中添加了如下数据源配置
<dataSource id="springdb" jndiName="jdbc/springdb">
<jdbcDriver javax.sql.XADataSource="com.mysql.cj.jdbc.Driver" libraryRef="mysqlJDBCLib"/>
<properties databaseName="spring_db" password="**********" portNumber="3306" serverName="localhost" user="root"/>
</dataSource>
<library id="mysqlJDBCLib">
<fileset dir="/opt/IBM/WebSphere/Liberty_16.0.0.4/usr/shared/resources/mysql" includes="mysql-connector-java-6.0.6.jar"/>
</library>
我得到以下堆栈跟踪
Caused by: java.lang.RuntimeException: java.sql.SQLNonTransientException: DSRA4000E: A valid JDBC driver implementation class was not found for the jdbcDriver dataSource[springdb]/jdbcDriver[default-0] using the library mysqlJDBCLib. [/opt/IBM/WebSphere/Liberty_16.0.0.4/usr/shared/resources/mysql/mysql-connector-java-6.0.6.jar]
at com.ibm.ws.resource.internal.ResourceFactoryTrackerData$1.getService(ResourceFactoryTrackerData.java:123)
... 77 more
Caused by: java.sql.SQLNonTransientException: DSRA4000E: A valid JDBC driver implementation class was not found for the jdbcDriver dataSource[springdb]/jdbcDriver[default-0] using the library mysqlJDBCLib. [/opt/IBM/WebSphere/Liberty_16.0.0.4/usr/shared/resources/mysql/mysql-connector-java-6.0.6.jar]
at com.ibm.ws.jdbc.internal.JDBCDriverService.classNotFound(JDBCDriverService.java:196)
... 77 more
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
at com.ibm.ws.classloading.internal.AppClassLoader.findClassCommonLibraryClassLoaders(AppClassLoader.java:499)
... 77 more
我已经尝试了以下
用 com.mysql.jdbc.Driver 和字符串替换 com.mysql.cj.jdbc.Driver 得到同样的错误
用 javax.sql.DataSource 替换 javax.sql.XADataSource 还是出现同样的错误
用 javax.sql.MysqlConnectionPoolDataSource 替换 javax.sql.XADataSource,同样的错误
将 mysql 连接器 jar 从 mysql-connector-java-6.0.6.jar 切换到 mysql-connector-java-5.1.45-bin.jar,仍然相同的错误(两个 jar 都在指定文件路径)
【问题讨论】:
-
我建议您只保留其中一个库,因为同时拥有它们可能会导致类路径出现问题。确保通过
ClassNotFoundException指向的类确实在 jar 中(您甚至可以解压缩 jar 并检查)。你试过javax.sql.DataSource="com.mysql.jdbc.Driver"的组合吗? -
是的,我删除了其中一个罐子并使用了 javax.sql.DataSource="com.mysql.jdbc.Driver"。我还解压缩了 jar 并确保驱动程序类在那里
-
当你使用
com.mysql.jdbc.Driver时,它是否还在寻找com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource? -
是的,它仍在寻找 com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
标签: java mysql spring jdbc websphere