Wildfly 10 Final postgres driver ClassCastException - jdbc

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

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>

Related

wildfly - installing postgres driver jar

I am having difficulty installing the postgres driver. I've tried a bunch of things:
https://docs.jboss.org/author/display/WFLY10/Application+deployment
a. tried "deploying" the JAR (both from CLI and admin console UI)
https://sites.google.com/site/jmdstips/jboss-wildfly/postgresql-on-wildfly---xa-datasource
a. tried putting module definition in modules/org/postgresql ...
b. tried putting module definition in modules/system/layers/base/org/postgresql
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="org.postgres">
<resources>
<resource-root path="postgresql-9.4.1212.jre7.jar" />
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
And:
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="postgresql" module="org.postgresql">
<datasource-class>org.postgresql.Driver</datasource-class>
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
</drivers>
After all of that, I get this error. So, I think wildfly can "see" the module, but something is awry.
23:24:15,889 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "postgresql")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [org.postgresql]"
short answer: put the driver in the /wildfly/standalone/deployments folder, it will deploy the driver automatically
It turns out I used "org.postgres" for the module name in standalone.xml instead of "org.postgresql" which is what I declared it as inside the module.xml
I also encountered this error and it was due to the module.xml not having the correct resource-root

Wildfly Failed to Load Module for Oracle Driver

I'm attempting to add an Oracle DB datasource to Wildfly 10. Here's what I have:
<wildfly-home>\modules\com\oracle\ojdbc6\main\
module.xml
ojdbc6.jar
module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:Wildfly:module:1.0" name="com.oracle.ojdbc6">
<resources>
<resource-root path="ojdbc6.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.resource.api"/>
<module name="javax.transaction.api"/> <!-- See * below -->
</dependencies>
</module>
* I have tried both with and without the line <module name="javax.transaction.api/>. Some examples I've found online include it. Some do not. It seems to make no difference with whether the error occurs or not.
ojdbc6.jar was copied from <oracle-home>\jdbc\lib\ojdbc6.jar.
I have modified <wildfly-home>\standalone\configuration\standalone.xml to include this within the <drivers> tag:
<driver name="oraclethin" module="com.oracle.ojdbc6">
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
This error message is being spat out when I cd into <wildfly-home>\bin and run .\standalone.bat:
15:17:13,415 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "oraclethin")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [com.oracle.ojdbc6]"
I've triple checked the spelling on everything. I've tried taking out some lines (and putting them back when nothing changes). Is anyone seeing what I'm missing?
Use xmlns="urn:jboss:module:1.0"
As described in https://docs.jboss.org/author/display/MODULES/Module+descriptors
what solve the issue for me was to enlarge the timeout connection on the standalone.xml file on jboss
<system-properties>
...
<property name="jboss.as.management.blocking.timeout" value="6000"/>
</system-properties>

Db2 Driver/Datasource setup on wildfly: Failed to load module for driver [com.ibm]

I am wanting to configure the data source for db2 on my wildfly server (Wildfly.8.0.0-Final and 8.1.0 as well.) and am running into some problems doing so.
My research tells me this is a two step process
install the drivers as a module in the %JBOSS_HOME%/modules/com/ibm/main dir.
configure the datasources subsystem to include this module as a driver in your connection settings.
So far I have installed the module under the following structure with the following module.xml:
modules/
`-- com/
`-- ibm/
`-- main/
|-- db2jcc4.jar
|-- db2jcc_license_cu.jar
|-- db2jcc_license_cisuz.jar
`-- module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.ibm">
<resources>
<resource-root path="db2jcc4.jar"/>
<resource-root path="db2jcc_license_cu.jar"/>
<resource-root path="db2jcc_license_cisuz.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="sun.jdk"/>
</dependencies>
</module>
There is no space before the <?...?> in the xml file. the module name is "com.ibm" and the datasource is as follows:
<subsystem xmlns="urn:jboss:domain:datasources:2.0">
<datasources>
<datasource jndi-name="java:/jdbc/MyDS" pool-name="MyDS" enabled="true" use-java-context="true">
<xa-datasource-property name="ServerName">myIP</xa-datasource-property>
<xa-datasource-property name="PortNumber">1234</xa-datasource-property>
<xa-datasource-property name="DatabaseName">MyDB</xa-datasource-property>
<xa-datasource-property name="DriverType">4</xa-datasource-property>
<driver>ibmdb2</driver>
<pool>
<min-pool-size>0</min-pool-size>
<max-pool-size>50</max-pool-size>
</pool>
<security>
<user-name>bob</user-name>
<password>isyouruncle</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.db2.DB2ValidConnectionChecker"/>
<stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.db2.DB2StaleConnectionChecker"/>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.db2.DB2ExceptionSorter"/>
</validation>
</datasource>
<drivers>
<driver name="ibmdb2" module="com.ibm">
<xa-datasource-class>com.ibm.db2.jcc.DB2XADatasource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
The loading up of the server produces this error:
12:49:01,228 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 9) JBAS014613: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "ibmdb2")
]) - failure description: "JBAS010441: Failed to load module for driver [com.ibm]"
Which in turn causes my datasource declaration to fail loading as the driver is missing.
I am using older documentation as a guide because there doesn't seem to be any available for wildfly as yet. this documentation shows some promise but it seems a little out of date. If anyone has had any experience setting this up then Your help would be much appreciated.
I want to connect to DB2 9.7.
Please and thank you.
try replacing :
<resources-root path="db2jcc4.jar"/>
<resources-root path="db2jcc_license_cu.jar"/>
<resources-root path="db2jcc_license_cisuz.jar"/>
by
<resource-root path="db2jcc4.jar"/>
<resource-root path="db2jcc_license_cu.jar"/>
<resource-root path="db2jcc_license_cisuz.jar"/>
Remove the s from resources-route!
You could try to enable jboss.jdbc.spy = TRACE and add spy="true" to the datasource.
<datasource jndi-name="..." ... spy="true">
and
<logger category="jboss.jdbc.spy">
<level name="TRACE"/>
</logger>
This is normally to debug the JDBC, but perhaps it shows more on the loading of the driver as well.
Also you definitely need the resource-root without s.
I had the same issue. I resolved it by removing these two lines from module.xml:
<resource-root path="db2jcc_license_cu.jar"/>
<resource-root path="db2jcc_license_cisuz.jar"/>
I don't have a specific explanation as to why this worked.
This is not the solution to your problem but a reference for future visitors who (like me) come to this question by search of the same error message:
Today I had the same problem, for me it was an error in module.xml and standalone-full.xml. In both cases the module name was given as com.ibm.main, but it should have been com.ibm.
So in short: If you encounter this message and double checking the config files doesn't help, rewrite them.
jar files in module main folder should be added to the module.xml as
<resources>
<resource-root path="db2jcc4.jar"/>
<resource-root path="db2jcc_license_cu.jar"/>
</resources>
If you're using db2jcc.jar and not db2jcc4.jar and as you're defining a standard (non-XA) datasource, perhaps it helps to spedicfy the driver class too.
<driver-class>com.ibm.db2.jcc.DB2Driver</driver-class>
Everything is correct, just make s capital for (DB2XADatasource) as below:
<xa-datasource-class>com.ibm.db2.jcc.DB2XADataSource</xa-datasource-class>

Issue configuring JBoss EAP 6.1 with hibernate 3.6

I'm trying to deploy an EAR file in my local server but it seems it's still trying to use hibernate 4 (the default option, I guess).
What I have already done:
I've added a hibernate 3 module in $JBOSS_HOME$\modules\org.hibernate\3 with this module.xml file:
<module xmlns="urn:jboss:module:1.0" name="org.hibernate" slot="3">
<resources>
<resource-root path="hibernate3.jar"/>
<resource-root path="commons-collections-3.1.jar"/>
<resource-root path="jta-1.1.jar"/>
<resource-root path="javassist-3.12.0.GA.jar"/>
<resource-root path="antlr-2.7.6.jar"/>
<resource-root path="slf4j-api-1.6.1.jar"/>
<resource-root path="dom4j-1.6.1.jar"/>
<!-- Insert other Hibernate 3 jars to be used here -->
</resources>
<dependencies>
<module name="org.jboss.as.jpa.hibernate" slot="3"/>
<module name="asm.asm"/>
<module name="javax.api"/>
<module name="javax.persistence.api"/>
<module name="javax.transaction.api"/>
<module name="com.ibm.db2" />
<module name="org.infinispan"/>
</dependencies>
</module>
I've created the data source in standalone-full-ha.xml:
<datasource jndi-name="java:jboss/datasources/txdb" pool-name="txdbDS" enabled="true" use-java-context="true">
<connection-url>jdbc:db2://156.24.30.103:50000/TX_LSPDB</connection-url>
<driver>DB2Driver</driver>
<security>
<user-name> .... </user-name>
<password> .... </password>
</security>
</datasource>
My persistence.xml file has the following entry:
<persistence-unit name="esdb">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/txdb</jta-data-source>
<class>com.gtech.commerce.UidBlockPool</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/>
<property name="jboss.as.jpa.providerModule" value="org.jboss.as.jpa.hibernate:3" />
</properties>
</persistence-unit>
And this is what I get when I try to deploy:
Caused by: java.lang.ClassCastException: org.springframework.orm.hibernate3.LocalJtaDataSourceConnectionProvider incompatible with org.hibernate.service.jdbc.connections.spi.ConnectionProvider at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:189) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1] ... 107 more
Any idea about what I am missing?
UPDATE: I haven't found a solution, so I did the obvious workaround: I am using hibernate 3 bundled with the application, ignoring any module
Imho the problem comes from the fact that the jboss datasource built-in connection pool rely on the default persistence implementation provided with the server.
you can try to override the server datasource configuration
see https://access.redhat.com/site/documentation/en-US/JBoss_Enterprise_BRMS_Platform/5/html/BRMS_Administrator_Guide/Configuring_a_Datasource_for_JBoss_Enterprise_Application_Platform_6.html
But i don't know if you can specify the connection pool provider.
You could try otherwise to set up a custom datasource
see http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch01.html
please consider than you won't be any more in this case: JDBC connections obtained from a JNDI datasource automatically participate in the container-managed transactions of the application server.
and will have to properly configure the transaction factory.
As a more general comment I'll advise not to override provided implementation when using a Java EE application server.
If you wan't to use hibernate 3 switch to Jboss 6.0 or do not rely on the built-in java EE container features (and in this case switch to something lighter like jetty or tomcat)

Jboss 7.1.1 Final Unable to create Web Service Client

I have a ws client created using maven with artifact maven-jaxws-tools-plugin and goal wsconsume.
Once I try to initiate the client I am having below error.
03:25:03,928 ERROR [org.quartz.core.JobRunShell] (quartzScheduler_Worker-1) Job DEFAULT.rcdLogTrackerJobDetail threw an unhandled Exception: : java.lang.NoClassDefFoundError: org/springframework/beans/BeansException
at org.jboss.wsf.stack.cxf.client.configuration.JBossWSBusFactory.getSpringBusFactory(JBossWSBusFactory.java:120)
at org.jboss.wsf.stack.cxf.client.configuration.JBossWSBusFactory.createBus(JBossWSBusFactory.java:54)
at org.jboss.wsf.stack.cxf.client.ProviderImpl.setValidThreadDefaultBus(ProviderImpl.java:213)
at org.jboss.wsf.stack.cxf.client.ProviderImpl.createServiceDelegate(ProviderImpl.java:140)
at javax.xml.ws.Service.<init>(Service.java:57) [jboss-jaxws-api_2.2_spec-2.0.0.Final.jar:2.0.0.Final]
.....
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:113) [spring-context-support-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.quartz.core.JobRunShell.run(JobRunShell.java:223) [quartz-1.8.6.jar:]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549) [quartz-1.8.6.jar:]
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.BeansException from [Module "org.apache.cxf:main" from local module loader #4f2c61fe (roots: /opt/extcomp/jboss-as-7.1.1.Final/modules)]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
... 14 more
03:25:03,949 ERROR [org.quartz.core.ErrorLogger] (quartzScheduler_Worker-1) Job (DEFAULT.rcdLogTrackerJobDetail threw an exception.: org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NoClassDefFoundError: org/springframework/beans/BeansException]
at org.quartz.core.JobRunShell.run(JobRunShell.java:234) [quartz-1.8.6.jar:]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549) [quartz-1.8.6.jar:]
Caused by: java.lang.NoClassDefFoundError: org/springframework/beans/BeansException
at org.jboss.wsf.stack.cxf.client.configuration.JBossWSBusFactory.getSpringBusFactory(JBossWSBusFactory.java:120)
at org.jboss.wsf.stack.cxf.client.configuration.JBossWSBusFactory.createBus(JBossWSBusFactory.java:54)
at org.jboss.wsf.stack.cxf.client.ProviderImpl.setValidThreadDefaultBus(ProviderImpl.java:213)
at org.jboss.wsf.stack.cxf.client.ProviderImpl.createServiceDelegate(ProviderImpl.java:140)
at javax.xml.ws.Service.<init>(Service.java:57) [jboss-jaxws-api_2.2_spec-2.0.0.Final.jar:2.0.0.Final]
.....
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:113) [spring-context-support-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.quartz.core.JobRunShell.run(JobRunShell.java:223) [quartz-1.8.6.jar:]
... 1 more
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.BeansException from [Module "org.apache.cxf:main" from local module loader #4f2c61fe (roots: /opt/extcomp/jboss-as-7.1.1.Final/modules)]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
... 14 more
I did some search and see that there is a bug of JBoss 7.1.1 and can be fixed just by doing some manual stuff like; creating a new module and adding it to apache cxf module etc..
I did all these stuff. But couldn't get it working.
Can someone help me, If I am doing something wrong.
by the way; since the client has been created using wsconsume, I also tried to add the module dependency (spring module created by me) to jboss cxf stuff as well. But not worked.
I think I found the issue. It was a typo on my manually-created spring module.
I am not sure if we need to consider this as answer but the issue was a typo.
The solution I followed was.
http://blog.brunoborges.com.br/2012/06/jboss-711-and-cxf-ws-client.html
and of course you need to use correct jar versions while following the above guide.
The post indicated by #Olgum is realy good and help me. But, the link to module.xml is broken. So in order to preserve it for future, I'll post the solution below.
On the jboss-as-7.1.1-Final folder ([JBOSS_HOME]), create this path: modules/org/springframework/spring/main
Create the module.xml file (below) inside the newly created folder
Download and put the jar files into the same folder (the list of jar is inside the module.xml)
Open this file [JBOSS_HOME]/modules/org/apache/cxf/main/module.xml
At the end of this file, make sure you have this module dependency <module name="org.springframework.spring" />
Spring module.xml content:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.springframework.spring">
<resources>
<resource-root path="spring-aop-3.1.4.RELEASE.jar"/>
<resource-root path="spring-asm-3.1.4.RELEASE.jar"/>
<resource-root path="spring-beans-3.1.4.RELEASE.jar"/>
<resource-root path="spring-context-3.1.4.RELEASE.jar"/>
<resource-root path="spring-context-support-3.1.4.RELEASE.jar"/>
<resource-root path="spring-core-3.1.4.RELEASE.jar"/>
<resource-root path="spring-expression-3.1.4.RELEASE.jar"/>
<resource-root path="spring-jdbc-3.1.4.RELEASE.jar"/>
<resource-root path="spring-orm-3.1.4.RELEASE.jar"/>
<resource-root path="spring-oxm-3.1.4.RELEASE.jar"/>
<resource-root path="spring-tx-3.1.4.RELEASE.jar"/>
<resource-root path="spring-web-3.1.4.RELEASE.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.jms.api"/>
<module name="javax.annotation.api"/>
<module name="javax.servlet.api"/>
<module name="org.apache.commons.logging"/>
<module name="org.jboss.vfs"/>
</dependencies>
</module>
I had the same error when instantiating a webservice client, but I couldn't change the JBoss modules (corporate environment). This issue took my day but I finally solved it by adding a dependency to cxf-rt-frontend-jaxws version 2.7.4.
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
Hope it helps.
Julian's solution got me going in the right direction, but there were still missing dependencies which were resolved by looking at this solution:
Apache CXF Exception: java.lang.RuntimeException: Could not find conduit initiator for address
Therefore, I added the following to my pom:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>

Resources