【发布时间】:2020-05-30 11:28:37
【问题描述】:
我在服务器 (Ubuntu 18.04) 上安装了全新的 tomcat 9。我正在尝试设置 treeanno (https://github.com/nilsreiter/treeanno/releases) 并部署 github 存储库中提供的 Web 应用程序存档 (war)。 我使用 tomcat manager 应用程序来部署 war 文件,并按照此描述配置 tomcat 以使用相应的数据库资源:https://github.com/nilsreiter/treeanno/blob/master/INSTALL.md。 根据粗略的描述,这个要在tomcat安装的context.xml中添加:
<Resource name="treeanno/jdbc" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="USERNAME" password="PASSWORD" driverClassName="com.mysql.jdbc.Driver"
url="DATABASE URL"/>
由于我是 tomcat 的新手,我不清楚我需要设置哪些属性,尤其是“url”。 如果我尝试访问该应用程序,我会收到以下错误,指出由于 url 不足,无法建立数据库连接:
Type Exception Report
Message An exception occurred processing [/index.jsp] at line [12]
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.apache.jasper.JasperException: An exception occurred processing [/index.jsp] at line [12]
9: doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
10: doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
11: omit-xml-declaration="false" />
12: <sql:query var="rs" dataSource="treeanno/jdbc" sql="select id, username from treeanno_users">
13: </sql:query>
14: <html xmlns="http://www.w3.org/1999/xhtml">
15: <head>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:626)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:500)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: Cannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'jdbc:mysql:3306'"
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:666)
org.apache.jsp.index_jsp._jspService(index_jsp.java:270)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: Cannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'jdbc:mysql:3306'"
org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:285)
org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:168)
org.apache.jsp.index_jsp._jspx_meth_sql_005fquery_005f0(index_jsp.java:296)
org.apache.jsp.index_jsp._jspService(index_jsp.java:134)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
我已经发现该 url 应该链接到包含密码和用户的数据库服务器,但这似乎不适合此配置文件。
我在这里找到了以下内容 (https://ci.apache.org/projects/tomcat/tomcat9/docs/jndi-datasource-examples-howto.html):
url=jdbc:mysql://localhost:3306/javatest"/
但调整端口等不起作用: url=jdbc:mysql://localhost:8080/TreeAnno-1.0.2"/
现在,我需要如何制定 url 以允许应用连接/启动 MySQL 数据库?
【问题讨论】:
-
<tomcat-root>/lib中有mysql驱动jar吗? -
jdbc:mysql:3306不是有效的 JDBC 连接 url...无论如何,听起来您在 tomcat 本身的 claspath 上没有 MySQL Connector/J 驱动程序。