(嵌入式Tomcat 7.0.59,gradle 2.13,HikariCP 2.4.6,mysql-connector-java 6.0.2)
我想在我的Web应用程序中创建连接池(mysql)。 当我执行gradle tomcatRun时,我收到以下消息:
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
at com.zaxxer.hikari.util.UtilityElf.createInstance(UtilityElf.java:89)
at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:294)
at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:91)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:101)
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:71)
at [my package].DbContextListener.initDataSource(DbContextListener.java:40)
at [my package].DbContextListener.contextInitialized(DbContextListener.java:27)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5524)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at com.zaxxer.hikari.util.UtilityElf.createInstance(UtilityElf.java:76)
... 15 more
我发现tomcat可能不包含dbcp-jar,所以我尝试通过gradle添加它:
compile 'org.apache.tomcat:tomcat-jdbc:7.0.59'
但没有改变
有谁能解释我应该怎么做?