【问题标题】:Wildfly 10 Final postgres driver ClassCastExceptionWildfly 10 Final postgres 驱动程序 ClassCastException
【发布时间】:2016-07-13 23:29:05
【问题描述】:

最终有人可以帮助我。目前,当使用 postgres 驱动程序启动 wildfly 10 Final 但使用相同的设置 wildfly 10 CR4 将启动时,我遇到了一个非常奇怪的问题。

我得到的异常如下:

Caused by: javax.resource.ResourceException: IJ031089: Failed to load datasource: org.postgresql.Driver
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getDataSource(LocalManagedConnectionFactory.java:650)
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:311)
    ... 6 more
Caused by: java.lang.ClassCastException: org.postgresql.Driver cannot be cast to javax.sql.DataSource
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getDataSource(LocalManagedConnectionFactory.java:633)
    ... 7 more

奇怪的是,它适用于 Wildfly 10 CR4,但不适用于最终版本的 Wildfly 10 Final。任何想法? 对我来说,这看起来像是一个类加载器问题,但我不是使用 wildfly 追踪它的专家。

我的modules/org/postgres/main/module.xml

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
  <resources>
    <resource-root path="postgresql-9.4.1208.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
    <module name="javax.servlet.api" optional="true"/>
  </dependencies>
</module>

standalone.xml中我的驱动定义

<driver name="postgres" module="org.postgres">
    <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
    <datasource-class>org.postgresql.Driver</datasource-class>
</driver>

Java JDK 为:jdk1.8.0_73

非常感谢任何帮助解决我的问题。

提前谢谢

/大卫

【问题讨论】:

    标签: jdbc postgresql-9.4 wildfly-10


    【解决方案1】:

    实现数据源的类名是:

    org.postgresql.ds.PGSimpleDataSource
    

    org.postgresql.ds.PGPoolingDataSource
    

    https://jdbc.postgresql.org/documentation/head/ds-ds.html

    我假设 Wildfly 将管理连接,因此您可能不需要池化 DataSource,只需要简单的: 所以应该是

    <driver name="postgres" module="org.postgres">
        <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
        <datasource-class>org.postgresql.ds.PGSimpleDataSource</datasource-class>
    </driver>
    

    【讨论】:

    • ConnectionPoolDataSource 不是(或不应该是)DataSource。对于PGConnectionPoolDataSource,它只实现ConnectionPoolDataSource。据我所知,WildFly 在这里期望 DataSource
    • 非常感谢你们俩!阅读您的回复听起来很合理;) datasource-class 需要一个数据源。无论如何,非常感谢!
    猜你喜欢
    • 2018-06-08
    • 2017-07-06
    • 2016-12-07
    • 1970-01-01
    • 2016-01-11
    • 2017-04-13
    • 1970-01-01
    • 1970-01-01
    • 2017-03-14
    相关资源
    最近更新 更多