在 ubuntu 14.04 操作系统上使用 tomcat 7、tomcat-jdbc.jar、p6spy 2.14、C3p0 和 hibernate 。
我的 p6spy.jar 位于我的 cp 中的/usr/share/tomcat7/lib 中。 spy.properties 文件正在通过系统属性正确传递给 tomcat。
hibernate.cfg.xml相关部分
<hibernate-config>
<driver_class>com.p6spy.engine.spy.P6SpyDriver</driver_class>
<url>jdbc:p6spy:mysql://myhost:3306/mydatabase</url>
<username>xxx</username>
<password>xxx</password>
</hibernate-config>
当我明确添加 driverlist=com.mysql.jdbc.Driver
给 spy.properties tomcat 抛出这个异常:
Warning: Error registering driver names: [com.mysql.jdbc.Driver]
Caused By: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
com.p6spy.engine.spy.P6DriverNotFoundError: Error registering driver names: [com.mysql.jdbc.Driver]
Caused By: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at com.p6spy.engine.spy.P6ModuleManager.loadDriversExplicitly(P6ModuleManager.java:220)
at com.p6spy.engine.spy.P6ModuleManager.<init>(P6ModuleManager.java:130)
at com.p6spy.engine.spy.P6ModuleManager.initMe(P6ModuleManager.java:73)
at com.p6spy.engine.spy.P6ModuleManager.<clinit>(P6ModuleManager.java:61)...
当我删除驱动程序列表设置时 - 或者像上面那样放入它时,我总是得到这个异常 - 奇怪的是 p6spy 前缀被从我的连接字符串中截断了:
WARN [com.mchange.v2.resourcepool.BasicResourcePool]: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@309efc1f -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: Unable to find a driver that accepts jdbc:mysql://devtestrds.cdsug1b8degu.us-west-1.rds.amazonaws.com:3306/biz_eng
at com.p6spy.engine.spy.P6SpyDriver.findPassthru(P6SpyDriver.java:119)
at com.p6spy.engine.spy.P6SpyDriver.connect(P6SpyDriver.java:94)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
我不知道为什么 p6spy 找不到这个驱动程序。这可能是某种类加载错误吗?任何线索表示赞赏
最佳答案
使用 P6Spy 2.X,您需要在 spy.properties 中设置 driverlist=com.mysql.jdbc.Driver。
P6Spy 1.3 会自动注册驱动程序,这有时会导致重复注册。这就是为什么1.3也有注销驱动的设置。
关于java - p6spy 找不到适合 com.mysql.jdbc.Driver 的驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33966364/