ClassNotFoundException when upgraded to Tomcat 8

淺唱寂寞╮ 提交于 2019-12-03 06:46:07

The name of the default factory changed between Tomcat 7 and Tomcat 8. A couple of attribute names also changed. This is all as a result of switching from DBCP 1.x to DBCP 2.x in Tomcat 8. You want the following in your META-INF/context.xml file:

<!-- PostgreSQL Datasource -->
<Resource auth="Container"
          driverClassName="org.postgresql.Driver"
          factory="org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory"
          maxTotal="50"
          maxIdle="10"
          maxWaitMillis="-1"
          name="jdbc/mydb"
          type="javax.sql.DataSource"
          url="jdbc:postgresql://myorg.corp.net:5432/mydb"
          username="abc"
          password="def" />

Since this factory is used by default for resources of type javax.sql.DataSource you can just drop that attribute all together. The other changes were:

maxActive -> maxTotal
maxWait   -> maxWaitMillis
Imran Bhat

You need tomcat-dbcp-8.0.0-RC1.jar in your tomcat8 lib folder. The package structure for org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory in commons-dbcp.jar is different from other tomcat versions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!