我们使用带有postgres数据源的Wildfly 10(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中,这是肯定的,否则,在部署期间不会有试验来实例化它。 任何帮助都非常感谢!!
答案 0 :(得分:2)
显然,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)