Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datasource configuration in wildfly 10

I am trying to configure a PostgreSQL datasource in Wildfly 10 Application Server on Mac OS. I am doing what the instructions prescribe. I have created an order:

/wildfly-10.1.0.Final/modules/system/layers/base/org/postgresql/main. 

In this order I have put the JDBC driver:

postgresql-9.3-1104.jdbc4.jar

and I have created a module.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="org.postgresql“>
  <resources>
    <resource-root path="postgresql-9.3-1104.jdbc4.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
  </dependencies>
</module>

In the standalone.xml file I have created the datasource under datasources:

     <datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true"
                        use-java-context="true">
   <connection-url>jdbc:postgresql://localhost:5432/testdb</connection-url>
         <driver>postgresql</driver>
            <security>
             <user-name>user</user-name>
             <password>password</password>
            </security>
            <validation>
              <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"></valid-connection-checker>
              <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"></exception-sorter>
     </validation>
   </datasource>

and drivers as:

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

However it is impossible the datasource is not installed and when I start the server I get the message (error):

ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
            ("subsystem" => "datasources"),
            ("data-source" => "PostgresDS")
        ]) - failure description: {
            "WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.postgresql"],
            "WFLYCTL0180: Services with missing/unavailable dependencies" => [
                "org.wildfly.data-source.PostgresDS is missing [jboss.jdbc-driver.postgresql]",
                "jboss.driver-demander.java:jboss/datasources/PostgresDS is missing [jboss.jdbc-driver.postgresql]"
            ]
        }
    [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
        ("subsystem" => "datasources"),
        ("data-source" => "PostgresDS")
    ]) - failure description: {
        "WFLYCTL0412: Required services that are not installed:" => [
            "jboss.jdbc-driver.postgresql",
            "jboss.jdbc-driver.postgresql"
        ],
        "WFLYCTL0180: Services with missing/unavailable dependencies" => [
            "org.wildfly.data-source.PostgresDS is missing [jboss.jdbc-driver.postgresql]",
            "jboss.driver-demander.java:jboss/datasources/PostgresDS is missing [jboss.jdbc-driver.postgresql]",
            "org.wildfly.data-source.PostgresDS is missing [jboss.jdbc-driver.postgresql]"
        ]
    }

It seems, that wildfly maybe does not find the module. Any ideas what causes this problem? Is anything wrong in my configuration?

like image 408
arjacsoh Avatar asked Apr 14 '17 09:04

arjacsoh


People also ask

What is datasource in Wildfly?

A Datasource is the component used by Enterprise applications to connect to the database. The datasource, in turn, uses a Driver to communicate with the underlying database. For this reason, for WildFly to provide database integration, it needs a Driver and a Datasource.

What is datasource configuration?

Spring boot datasource configuration is nothing but the factory of connection which was used in a physical data source. Spring boot datasource uses the database credential to set up connections between the database server, it is alternative to the facility of Driver Manager.


1 Answers

I'd like to recommend a change to your process. While you certainly can do this by hand, if you script this you can do it again with repeatability.

This is dependent on the jboss-cli.sh. I have a script that looks like:

embed-server --std-out=echo --server-config=standalone.xml

batch

module add --name=org.postgres --resources=/tmp/postgresql-42.0.0.jar --dependencies=javax.api,javax.transaction.api

/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)

/subsystem=datasources/data-source=myDataSource/:add(connection-url=jdbc:postgresql://localhost:5432/thedatabasename,driver-name=postgres,jndi-name=java:/jdbc/myDataSource,initial-pool-size=4,max-pool-size=64,min-pool-size=4,password=theDatabasePassword,user-name=theDatabaseUsername)

run-batch

This is run with:

bin/jboss-cli.sh --file=/path/to/file/wildflyconf.cli

The script starts by using the "embed-server" command so that your Wildfly instance does not need to be running. Then it starts a batch of commands to run as one unit.

The important part is that we create the module via the command line. You will have to put the PostgreSQL jar somewhere but other than that the script takes care of creating all of the needed files under "modules".

Next, we add the JDBC driver and then we create a Datasource based on the driver.

The advantage of a script is that you can check this into your source code control system and anyone can run it. It reduces the possibility of a typo and you don't need to manually create and modify files.

Just a thought. Having a repeatable process that your development team can use is always a useful thing.

like image 135
stdunbar Avatar answered Oct 05 '22 08:10

stdunbar