ResourceException:类名错误或未为 MysqlDataSource 设置类路径

ResourceException:类名错误或未为 MysqlDataSource 设置类路径

目前我正在关注 此链接

解决

Caused by: javax.resource.ResourceException: Class name is wrong or classpath is not set for : com.mysql.cj.jdbc.MysqlDataSource

因此,我将 mysql-connector-java-5.1.46.jar 添加到我的 glassfish 安装中,如下面的屏幕截图所示:

Glassfish 安装目录

重新启动 Glassfish 后,我的 .war 仍然无法部署,并显示相同的错误消息(下面的堆栈跟踪)

Caused by: javax.resource.ResourceException: Class name is wrong or classpath is not set for : com.mysql.cj.jdbc.MysqlDataSource
    at com.sun.gjc.common.DataSourceObjectBuilder.getDataSourceObject(DataSourceObjectBuilder.java:278)
    at com.sun.gjc.common.DataSourceObjectBuilder.constructDataSourceObject(DataSourceObjectBuilder.java:117)
    at com.sun.gjc.spi.ManagedConnectionFactoryImpl.getDataSource(ManagedConnectionFactoryImpl.java:1383)
    at com.sun.gjc.spi.DSManagedConnectionFactory.getDataSource(DSManagedConnectionFactory.java:163)
    at com.sun.gjc.spi.DSManagedConnectionFactory.createManagedConnection(DSManagedConnectionFactory.java:102)
    at com.sun.enterprise.resource.allocator.LocalTxConnectorAllocator.createResource(LocalTxConnectorAllocator.java:87)

有人知道如何解决这个问题吗?谢谢。

答案1

我通过将此依赖项添加到我的 pom.xml 中解决了这个问题

<dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.14</version>
        </dependency>

而不是将 mysql-connector-java-8.0.14.jar 放入 /payara5/glassfish/domains/domain1/lib。

相关内容