JDBC无法加载数据源的工厂类

时间:2014-01-22 14:51:32

标签: java mysql tomcat jdbc

我已经遇到这个问题好几天了,还没有设法修复它。我正在使用tomcat 7.0,我完全无法获得mysql数据库连接。我正在编写的应用程序是一个使用eclipse IDE的jsp动态网站。 TomCat 7启动时出现此错误:

WARNING: Failed to register in JMX: javax.naming.NamingException: Could not load resource factory class [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.jdbc.pool.DataSourceFactory]

我也遇到了这个错误:

javax.naming.NamingException: Could not load resource factory class [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.jdbc.pool.DataSourceFactory]
    at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:84)
    at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:826)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:145)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:814)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:145)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:814)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:145)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:814)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at test.General.Database.getConnection(Database.java:21)
    at test.Controller.LoginServlet.doPost(LoginServlet.java:43)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.jdbc.pool.DataSourceFactory
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:82)
    ... 31 more

当我看到这段代码时:

  try {
        Context ctx = new InitialContext();
        ds = (DataSource)ctx.lookup("java:comp/env/jdbc/chitchat");
      } catch (NamingException e) {
        e.printStackTrace();
      }

任何人都有任何想法我的问题是什么?我现在已经有了很多这样的事情,我真的想继续这样做。

4 个答案:

答案 0 :(得分:5)

你的类路径中不存在

org.apache.tomcat.jdbc.pool.DataSourceFactory jar

答案 1 :(得分:3)

您必须将tomcat-jdbc.jar放在tomcat lib文件夹中。它可以从link

下载

答案 2 :(得分:1)

什么jar是类org.apache.tomcat.jdbc.pool.DataSourceFactory?这个罐子在你的类路径中吗?

答案 3 :(得分:1)

我在使用Eclipse下载的Tomcat时遇到过这种情况。它遗漏了其他人提到的tomcat-jdbc.jar

我通过从Tomcat网站下载Tomcat zip并将Eclipse指向它来解决它。