Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use a datasource deployment descriptor with a driver module in Wildfly?

I can´t configure my datasource by using a "*-ds.xml" deployment descriptor with the database driver installed as module. The datasource *-ds.xml file is only valid if I deploy the database driver directly as jar. I think that If you choose to install the driver as a module you will have to configure the datasource in the standalone.xml directly. I would like the solution driver module + deployment descriptor.

like image 313
Laura Liparulo Avatar asked Feb 23 '16 16:02

Laura Liparulo


1 Answers

For your module to be visible to your application, you need to import the module to your application. You need jboss-deployment-structure.xml in your WEB-INF for your application, something like this:

<?xml version="1.0"?>
<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="org.postgresql" services="export">
                <imports>
                    <include path="META-INF**"/>
                    <include path="org**"/> 
                    <!-- assuming package of the driver is org.something -->
                </imports>
            </module>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

After that, the module and the driver should be visible for your app as well as to your *-ds.xml.

This is the way to say in *-ds.xml that you want to use a driver from a module:

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

(example using postgresql configuration, since you seem to be using that)

Edit: Tested this using following as postgresql-ds.xml:

<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_1.xsd">
    <datasource jndi-name="java:jboss/datasources/PostgeSQLDB " pool-name="PostgreSQLPool">
        <connection-url>jdbc:postgresql://localhost:5432/example
        </connection-url>
        <driver>postgres</driver>
        <pool>
            <max-pool-size>30</max-pool-size>
        </pool>
        <security>
            <user-name>postgresql</user-name>
            <password>postgresql</password>
        </security>
    </datasource>
    <drivers>
        <driver name="postgresql" module="org.postgresql">
            <xa-datasource-class>org.postgresql.xa.PGXADataSource
            </xa-datasource-class>
        </driver>
    </drivers>
</datasources>

However, with Wildfly 10 it gives this:

20:17:22,895 WARN  [org.jboss.as.connector] (MSC service thread 1-2) WFLYJCA0091: -ds.xml file deployments are deprecated. Support
 may be removed in a future version.
20:17:23,058 WARN  [org.jboss.as.connector.deployer.dsdeployer] (MSC service thread 1-1) WFLYJCA0012: <drivers/> in standalone -ds
.xml deployments aren't supported: Ignoring my-spring-app.war

I tested also on Wildfly 8.1, where the message is same. So it seems deploying a datasource configuration in -ds.xml is not supported and you need to create it in standalone.xml, referencing to module there. This forum link seems to confirm that.

What the link also says that you can define a data source using .ear/.war descriptors, which might be a better fit for your use case anyway. I created an example using a .war file and web.xml, located here, and this answer says you can do the same with .ears. Arguably it's even better than -ds.xml, since it is a standard.

like image 186
eis Avatar answered Sep 18 '22 03:09

eis