tomcat是apache的,所以它的JNDI数据源默认使用commons组件的DBCP连接池来配置。
如果想使用c3p0来配置数据源,就需要修改<Resource>标签里的部分配置选项,操作如下:
1. 肯定是引入c3p0对应的jar包或者maven依赖啦,
2. 按照上篇文章的配置方法, 将<Resource>标签的内容换成这个:
<Resource
name="jdbc/mysqlOfc3p0"
auth="Container"
factory="org.apache.naming.factory.BeanFactory"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
driverClass="com.mysql.jdbc.Driver"
idleConnectionTestPeriod="60"
maxPoolSize="50"
minPoolSize="2"
acquireIncrement="2"
user=""
password=""
jdbcUrl="jdbc:mysql://127.0.0.1:3306/数据库名"/>
最后别忘了在web.xml中加入:
<resource-ref>
<res-ref-name>jdbc/mysqlOfc3p0</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>