Servlet.service() for servlet [...] 在路径 [/...] 的上下文中抛出异常 [Servlet 执行抛出异常] 具有根本原因

Servlet.service() for servlet [...] in context with path [/...] threw exception [Servlet execution threw an exception] with root cause

我正在尝试设置数据源连接;我实际得到的错误是 java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z

但是正上方弹出标题错误

--

我有一个 caffeJdbc.java 带有此数据源设置的 servlet

Context ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx.lookup("java:comp/env/jdbc/caffeDB");
Connection con = dataSource.getConnection();

--

这是项目web.xml设置,带有servlet映射和资源引用

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
    <servlet-name>tjdbc</servlet-name>
    <servlet-class>caffeJdbc</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>tjdbc</servlet-name>
    <url-pattern>/caffeJdbc</url-pattern>
</servlet-mapping>

<resource-ref>
    <res-ref-name>jdbc/caffeDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

--

server.xml

<GlobalNamingResources>
 <Resource name="jdbc/caffeDB" 
 global="jdbc/caffeDB"
 url="jdbc:mysql://localhost:3306/caffe"/>
</GlobalNamingResources>

--

这是 context.xml

<Context path="/JDBCDataSource">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <ResourceLink global="jdbc/caffeDB"
        name="jdbc/caffeDB"
        type="javax.sql.DataSource">
    </ResourceLink>
</Context>

我在 lib 目录和路径

中加载了 JDBC driver 和 commons-dbcp2-2.1.1

可能是您使用的 JDBC 驱动程序已过时,请检查,您可以查看 了解更多信息。