在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)...
当我退出驱动程序列表设置 - 或者像上面这样设置我总是得到这个例外 - 奇怪的是lloking像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不会找到这个驱动程序。这可能是某种类加载错误吗?任何线索赞赏
答案 0 :(得分:1)
使用P6Spy 2.X,您需要在spy.properties中设置driverlist = com.mysql.jdbc.Driver。
P6Spy 1.3会自动注册有时会导致重复注册的驱动程序。这就是为什么1.3还有取消注册驱动程序的设置。
答案 1 :(得分:0)
将mysql-connector-java-5.1.37-bin.jar添加到我的CP后,我能够通过p6spy驱动程序passthrough获取tomcat找到一个sql驱动程序 - 但后来我最终抛出一个链接异常。
我最终通过降级到p6spy v1.3并在相应的1.3格式spy.properties文件中设置“deregisterdrivers = true”,然后在我的tomcat7 / hibernate配置上正确运行p6spy。
答案 2 :(得分:0)
面对这个问题,今天发疯了。 滚动我的日志,我意识到Java 6不支持我的 ojdbc驱动程序。配置Java 7,一切顺利。