Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildfly 10 Final postgres driver ClassCastException

eventually somebody can help me. Currently I have a really strange problem when starting wildfly 10 Final with a postgres driver but with the same setting wildfly 10 CR4 will start up.

The exception I get is following:

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

The strange thing is, it works on wildfly 10 CR4 but not on the final version wildfly 10 Final. Any Idea? For me it looks like a class loader problem but I'm not that an expert with wildfly to track it down.

my 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>

My driver definition in 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 is: jdk1.8.0_73

Would really appreciate any help to fix my problem.

Thx in advance

/david

like image 908
David M. Avatar asked Dec 03 '22 15:12

David M.


1 Answers

The class name implementing a DataSource is either:

org.postgresql.ds.PGSimpleDataSource

or

org.postgresql.ds.PGPoolingDataSource

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

I assume Wildfly will manage the connections, so you probably don't need the pooling DataSource, only the simple: So it should be

<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>
like image 187
a_horse_with_no_name Avatar answered Dec 22 '22 00:12

a_horse_with_no_name