Tomcat、MySQL -> 无法为连接 URL 'null' 创建 class '' 的 JDBC 驱动程序

Tomcat, MySQL -> Cannot create JDBC driver of class '' for connect URL 'null'

我知道这看起来像是一个重复的问题,但已经尝试了 Whosebug 和其他论坛中的所有帖子,但无济于事。

阿帕奇 Tomcat 8.0.32 亚马逊 RDS 运行 MySQL 5.6 运行 tomcat 在 EC2 windows 服务器上

我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
...
  <resource-ref>
    <description>datasource</description>
    <res-ref-name>jdbc/bbDataSource</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
  </resource-ref>
...
</web-app>

Context.xml 坐在我的应用程序的 META-INF 文件夹中:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/ch">
   <Resource name="jdbc/bbDataSource"
        auth="Container"
        type="javax.sql.DataSource"
        username="********"
        password="********"
        driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql://*url*:3306/x?zeroDateTimeBehavior=convertToNull"/>
 </Context>

在 ServletContextListener 中创建数据源

try {
        dataSource = (DataSource) new InitialContext().lookup("java:comp/env/jdbc/bbDataSource");
        mLogger.log(Level.CONFIG, "Startup - AppContextServletListener - contextInitialized - Created dataSource object: {0}", dataSource);
        sce.getServletContext().setAttribute("dataSource", dataSource);
}

启动期间没有问题。 访问数据源时 tomcat 抛出上述错误。 并且 jar 文件位于 tomcat 的 lib 文件夹中(我怀疑这是问题所在,因为我也在同一个应用程序中使用休眠并且它能够毫无问题地访问数据库)。

我还注意到以下内容:$CATALINA_HOME/conf/Catalina/localhost 没有 'ch.xml' -> 尝试复制 context.xml 并重命名为 'ch.xml' 但无济于事。

server.xml -> 宿主节点下

 <Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="true">
        <Context path="/ch" docBase="ch"></Context>
        <Context path="/ch/asdasd" docBase="C:\xasdasd\asdasd">   </Context>

已修复:

在 Server.xml 中添加了上下文下的资源行 奇怪为什么需要定义两次?有什么线索吗?

 <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
     <Context path="/ch" docBase="ch">
        <Resource name="jdbc/bbDataSource"
             auth="Container"
             type="javax.sql.DataSource"
             username="********"
             password="********"
             driverClassName="com.mysql.jdbc.Driver"
             url="jdbc:mysql://x:3306/x?zeroDateTimeBehavior=convertToNull"/>
     </Context>
 </Host>