第一次在Struts1.2.x中使用数据源,谁知在Tomcat6启动时发生了错误,百度一搜,发现有许多网友也有这样的疑问,好不容易找到一位网友给的解决方法!
        先把问题描述清楚:
       1. Tomcat启动,当识别Struts1.2.x并使用了数据源的项目时,会有以下错误:
 
严重:  Initializing application data source datasource
java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
 ......
 
        我记得Tomcat已经自带dbcp包,但是用winRar打开tomcat-dbcp.jar,发现tomcat-dbcp.jar的内部结构:org.apache. tomcat.dbcp.dbcp.BasicDataSource!
      Tomcat6的doc也提到

JNDI Datasource HOW-TO

DBCP uses the Jakarta-Commons Database Connection Pool. It relies on number of Jakarta-Commons components:
  • Jakarta-Commons DBCP
  • Jakarta-Commons Collections
  • Jakarta-Commons Pool
These libraries are located in a single JAR at  $CATALINA_HOME/lib/tomcat-dbcp.jar.  However, only the classes needed for connection pooling have been included, and the packages have been renamed to avoid interfering with applications.
 
         解决办法:
        到 [url]http://www.apache.org/dist/commons/dbcp/binaries/[/url] 下载commons-dbcp-1.2.2.zip,以后可能会看到更高版本的!
        把里面的commons-dbcp-1.2.2.jar放到Tomcat目录下的lib文件夹!
 
       2. 再次启动Tomcat,又有新的错误;
 
严重: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown, so marking the servlet as unavailable.  Most likely, this is due to an incorrect or missing library dependency.
java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool
 at java.lang.Class.getDeclaredConstructors0(Native Method)
 ......
 
          解决办法:
         到 [url]http://www.apache.org/dist/commons/pool/binaries/[/url] 下载commons-pool-1.3.zip,把里面的commons-pool-1.3.jar放到Tomcat目录下的lib文件夹!
 
         这样就ok!在这里顺便提供这两个zip包的直接下载