Datasource configuration in wildfly 10

2019-05-08 03:24发布

问题:

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?

回答1:

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.



回答2:

You are defining your Driver class as a Datasource class :

<datasource-class>org.postgresql.Driver</datasource-class>

please use the correct element:

<driver-class>org.postgresql.Driver</driver-class>

just like @stdunbar showed you in his CLI command :

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


回答3:

in your file module.xml in the 2nd line change

<module xmlns="urn:jboss:module:1.3" name="org.postgresql“>

to

<module xmlns="urn:jboss:module:1.3" name="org.postgresql">

the ' " ' may be the problem in your module.xml



回答4:

Set the following system properties in standalone.xml and it should work fine:

-Dorg.kie.server.persistence.dialect=org.hibernate.dialect.PostgreSQLDialect

-Dorg.kie.server.persistence.ds=java:jboss/datasources/yourDataSource

<system-properties>
    <property name="org.kie.server.persistence.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
    <property name="org.kie.server.persistence.ds" value="java:jboss/datasources/ExampleDS"/>
</system-properties>