在 ubuntu 14.04 操作系统上使用 tomcat 7、tomcat-jdbc.jar、p6spy 2.14、C3p0 和休眠。
我的 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 找不到这个驱动程序。这可能是某种类加载错误吗?任何线索表示赞赏