java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource的解決方法

用Myeclipse开发struts时,配置struts-config中的data-sources,出现java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource的解决方法
struts-config.xml文件中的data-sources是这样配置的

  1. <data-sources>
  2. <data-source key="mysql" type="org.apache.commons.dbcp.BasicDataSource">
  3. <set-property property="autoCommit" value="true"/>
  4. <set-property property="driverClassName" value="com.mysql.jdbc.Driver"/>
  5. <set-property property="url" value="jdbc:mysql://localhost:3306/javajavajava"/>
  6. <set-property property="maxCount" value="10"/>
  7. <set-property property="minCount" value="1"/>
  8. <set-property property="username" value="root"/>
  9. <set-property property="password" value="admin"/>
  10. </data-source>
  11. </data-sources>

启动Tomcat,结果出现下面的错误:

信息: Starting Servlet Engine: Apache Tomcat/6.0.13
2007-12-17 19:31:06 org.apache.struts.action.ActionServlet initModuleDataSources
严重: Initializing application data source mysql
java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
at org.apache.struts.util.RequestUtils.applicationClass(RequestUtils.java:117)
at org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.java:143)
at org.apache.struts.action.ActionServlet.initModuleDataSources(ActionServlet.java:805)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:335)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4042)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4348)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2007-12-17 19:31:06 org.apache.catalina.core.ApplicationContext log
信息: Marking servlet action as unavailable
2007-12-17 19:31:06 org.apache.catalina.core.StandardContext loadOnStartup
严重: Servlet /huqianhao threw load() exception
javax.servlet.UnavailableException: Initializing application data source mysql
at org.apache.struts.action.ActionServlet.initModuleDataSources(ActionServlet.java:812)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:335)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4042)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4348)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2007-12-17 19:31:06 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2007-12-17 19:31:07 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2007-12-17 19:31:07 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/63 config=null
2007-12-17 19:31:07 org.apache.catalina.startup.Catalina start
信息: Server startup in 2848 ms

一看就知道是没有找到文件,但不知道是少了哪个jar包。网上搜了一下,只要把commons-pool.jar、commons-dbcp-1.2.2.jar和commons-collections-3.2.jar三个jar包加入classpath中就没问题拉!有人说只要前两个,我试了下好象不行哦。这几个jar包都可以在myeclipse安装文件下可以找到。只是版本号可能不一样而已Ctrl+F查找一下就OK拉!

更多相关文章
一周排行