How to add a PostgreSQL data source in WildFly 9.0?

I tried the tutorial at mastertheboss.com :

  • ./jboss-cli.sh
  • module add --name=org.postgres --resources=/tmp/postgresql-9.3-1101.jdbc41.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)
  • data-source add --jndi-name=java:/PostGreDS --name=PostgrePool --connection-url=jdbc:postgresql://localhost/postgres --driver-name=postgres --user-name=postgres --password=postgres

This tutorial works with WildFly 8.2, but it does not work with WildFly 9.0. The third step ends with an error message:

 { "outcome" => "failed", "failure-description" => "WFLYJCA0041: Failed to load module for driver [org.portgres]", "rolled-back" => true } 

How to add Postgres data source in WildFly 9.0?

+8
java postgresql jdbc datasource wildfly
source share
6 answers

I encountered the same error and behavior of WildFly 9. I am a complete newbie to WF, but after some research I found that the problem is with the module names. If I get this well, the actual package names in the module are used to resolve the path to module.xml.
I changed the steps to those below and it worked:

module add --name=org.postgresql --slot=main --resources=/usr/local/lib/postgresql-9.4-1201.jdbc4.jar --dependencies=javax.api,javax.transaction.api

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

I run wildfly 10 in docker:

 #ADD DATASOURCES RUN mkdir -p $JBOSS_HOME/modules/org/postgres/main COPY files/postgresql-9.4.1208.jre7.jar $JBOSS_HOME/modules/org/postgres/main/ COPY files/module.xml $JBOSS_HOME/modules/org/postgres/main/ COPY files/standalone.xml $JBOSS_HOME/standalone/configuration 

Where module.xml

 <module xmlns="urn:jboss:module:1.1" name="org.postgres"> <resources> <resource-root path="postgresql-9.4.1208.jre7.jar"/> </resources> <dependencies> <module name="javax.api"/> <module name="javax.transaction.api"/> <module name="javax.servlet.api" optional="true"/> </dependencies> </module> 

And the standalone driver contains:

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

then the data source can be:

 <datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true"> <connection-url>jdbc:postgresql://ndis-db:5432/postgres</connection-url> <driver>postgresql</driver> ... 

Please note that my ndis-db is docker postgres. In your case there may be localhost.

As I ended up with the error you mentioned: 1. Incorrect file name 2./modules/org ... etc contain a typo 3. module.xml with an error like modules.xml 4 ....

+7
source share

It is very simple, but it may take longer if you become new with JBOSS EAP / WilFly Use the following steps to create a data source:

  • Go to the bin folder on the server where the jboss-cli file (Power script) is present: right click on jboss-cli(power script file)--> Run with power shell (the console will open).

  • Add PostgreSQL JDBC driver as the main module .

module add --name = com.postgresql --resources = / path / to / postgresql-9.3-1102.jdbc4.jar --dependencies = javax.api, javax.transaction.api

  1. Register the PostgreSQL JDBC driver.

/ subsystem = data sources / JDBC driver = PostgreSQL: add (driver name = PostgreSQL, driver-module-name = com.postgresql, driver ha-DataSource class name = org.postgresql.xa.PGXADataSource)

  1. Add PostgreSQL data source.

data-source add --name = PostgresDS --jndi-name = java: jboss / PostgresDS --driver-name = postgresql --connection-url = jdbc: postgresql: // localhost: 5432 / postgresdb --user-name = admin --password = admin --validate-on-match = true --background-validation = false --valid-connection-checker-class-name = org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker Class name --exception-sorter = org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter

be careful with path path / to , this is the path where your downloded Postgresql-jdbc.jar is present .

+3
source share

Put your Postgres JDBC driver in the deployment folder (just expand). Now use the CLI console and enter the following command:

 data-source add --name=PostgresqlDS --jndi-name=java:jboss/datasources/PostgresqlDS --driver-name=postgresql-9.4-1201.jdbc41.jar --connection-url=jdbc:postgresql://localhost:5432/test --user-name=USER --password=PASSWORD 

Check if your driver is jdbc4.

I don't know why, but adding data sources using the web console does not work. By CLI it works.

The correct solution for extending JDBC drivers is to add a driver as a module for the server. In WildFly 9, you can do this using the cli console. You cannot do this by copying the JDBC JAR file (with xml) into the "module" folder, as in WildFly 8 .

Run the commands:

 module add --name=org.postgres --resources=postgresql-9.4-1201.jdbc41.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) 

To view the built-in drivers, type:

 /subsystem=datasources:installed-drivers-list 

With drivers creating data sources, it will be easy.

Please use the 9.0 final version. There are errors in CR.

Regards, Pawel M

+1
source share

You did not mention your version of java / jdbc. I just experienced the same problem, and this was due to a driver and Java 1.8 mismatch. With wildfly 9 update, have you also updated Java?

".jdbc41". The driver version is built for Java 1.7. Postgres has a matrix showing combinations of compatible versions of Java / JDBC and Postgres drivers. Maybe you need: postgresql-9.4.1209.jar (which is for 1.8 / jdbc42)

Then in the CLI (assuming domain mode and profile = full)

 module add --name=org.postgresql.Driver --resources=/tmp/postgresql-9.4.1209.jar connect /profile=full/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql.Driver",driver-class-name=org.postgresql.Driver) exit 
0
source share

Just a note: I checked the CLI commands taken from the tutorial mentioned regarding WildFly 10 and it works correctly when creating the JDBC driver and data source. In addition, I see that the error message contains an incorrect call to the module name ("org.portgres"):

 { "outcome" => "failed", "failure-description" => "WFLYJCA0041: Failed to load module for driver [org.portgres]", "rolled-back" => true } 

Disclaimer: I am the owner of mastertheboss.com

0
source share

All Articles