1

在 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 找不到这个驱动程序。这可能是某种类加载错误吗?任何线索表示赞赏

4

3 回答 3

2

对于 P6Spy 2.X,您需要在 spy.properties 中设置 driverlist=com.mysql.jdbc.Driver。

P6Spy 1.3 会自动注册有时会导致重复注册的驱动程序。这就是为什么 1.3 也有取消注册驱动程序的设置。

于 2015-11-30T16:57:27.680 回答
0

今天在面对这个问题时发疯了。向上滚动我的日志,我意识到Java 6 不支持我的 ojdbc 驱动程序。配置 Java 7,一切顺利。

于 2016-08-26T09:26:18.773 回答
0

将 mysql-connector-java-5.1.37-bin.jar 添加到我的 CP 后,我能够让 tomcat 通过 p6spy 驱动程序直通找到 sql 驱动程序 - 但后来我抛出了一个链接异常。

然而,我最终通过降级到 p6spy v1.3 并在相应的 1.3 格式 spy.properties 文件中设置“deregisterdrivers=true”,让 p6spy 在我的 tomcat7/hibernate 配置上正确运行。

于 2015-11-30T02:01:25.740 回答