gpt4 book ai didi

java - 包含 redshift jdbc 驱动程序 : Unable to instantiate driver class "com.amazon.redshift.jdbc.Driver": java. lang.NoClassDefFoundError

转载 作者:行者123 更新时间:2023-11-30 02:15:06 25 4
gpt4 key购买 nike

我们将 Wildfly 10 与 postgres 数据源一起使用(postgres 驱动程序在/modules 文件夹中提供),此外,还应附加 Redshift DB。

所以我关注了Configure a JDBC Connection with Apache Maven :
因此,我的父 POM 包括:

<repositories>
...
<repository>
<id>redshift</id>
<url>http://redshift-maven-repository.s3-website-us-east-1.amazonaws.com/release</url>
</repository>
</repositories>

<dependencies>
...
<dependency>
<groupId>com.amazon.redshift</groupId>
<artifactId>redshift-jdbc42</artifactId>
<version>1.2.10.1009</version>
</dependency>
</dependencies>

如果我知道部署我的 .war 文件,日志中很早就会出现以下警告:

INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.4)
INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0005: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 9.2)
WARN [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0003: Unable to instantiate driver class "com.amazon.redshift.jdbc.Driver": java.lang.NoClassDefFoundError: com/amazon/redshift/core/jdbc42/PGJDBC42DriverImpl

所以难怪稍后,如果我尝试访问数据库,我会得到

ERROR [stderr] (default task-64) java.sql.SQLException: No suitable driver found for jdbc:redshift://....
ERROR [stderr] (default task-64) at java.sql.DriverManager.getConnection(DriverManager.java:689)
ERROR [stderr] (default task-64) at java.sql.DriverManager.getConnection(DriverManager.java:208)

那我做错了什么?驱动程序打包在.war中,这是肯定的,否则部署时就不会尝试实例化它。非常感谢任何帮助!!

最佳答案

显然,redshift-jdbc42 依赖项已与“内部”JAR 文件打包在一起,这会导致某些上下文中的类加载出现问题。尝试更换

    <dependency>
<groupId>com.amazon.redshift</groupId>
<artifactId>redshift-jdbc42</artifactId>
<version>${amazon.redshift.version}</version>
</dependency>

    <dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-redshift</artifactId>
<version>${amazonaws.sdk.version}</version>
</dependency>
<dependency>
<groupId>com.amazon.redshift</groupId>
<artifactId>redshift-jdbc42-no-awssdk</artifactId>
<version>${amazon.redshift.version}</version>
</dependency>

(来源:https://forums.aws.amazon.com/thread.jspa?threadID=263573)

关于java - 包含 redshift jdbc 驱动程序 : Unable to instantiate driver class "com.amazon.redshift.jdbc.Driver": java. lang.NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48825949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com