spring下配置tomcat jdbc pool 報找不到"com.mysql.jdbc.Driver"類

初始配置以下:java

<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource">
   <property name="url" value="${demo.jdbc.url}" />
   <property name="username" value="${demo.jdbc.username}" />
   <property name="password" value="${demo.jdbc.password}" />
   <property name="driverClassName" value="${demo.jdbc.driverClassName}" />
</bean>

啓動tomcat報異常信息:mysql

嚴重: Unable to create initial connections of pool.
java.sql.SQLException: com.mysql.jdbc.Driver
   at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254)
    at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:701)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:635)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:486)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:144)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:127)spring

    ....sql

最後解決方式兩種:數據庫

一:在tomcat/lib目錄添加數據庫鏈接jar包apache

二:tomcat目錄不變,修改配置以下:tomcat

<bean id="dataSourceTemplate" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
   <property name="url" value="${demo.jdbc.url}" />
   <property name="username" value="${demo.jdbc.username}" />
   <property name="password" value="${demo.jdbc.password}" />
   <property name="driverClassName" value="${demo.jdbc.driverClassName}" />
</bean>

<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource">
   <property name="dataSource" ref="dataSourceTemplate"/>
</bean>

我的推薦第二種方法。url

具體緣由參考文章:https://stackoverflow.com/questions/4790589/sqlexception-w-tomcat-7-0-jdbc-connection-pool-and-mysqlget

相關文章
相關標籤/搜索