Oracle DB Connection: failure description: "WFLYJCA0041: Failed to load module for driver [com.oracle] - wildfly

Setting up connection to Oracle19C from Keycloak 12.0.3
Receiving message: "failure description: "WFLYJCA0041: Failed to load module for driver [com.oracle]"
I've relooked x100 and can't seem to find what is missing. Could any kind soul review the below for what I have missed?
JAR File path:
/modules/system/layers/keycloak/com/oracle/main
module.xml
ojdbc10.jar
standalone.xml
<datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
<connection-url>jdbc:oracle:thin:#DBURL:1521:SID</connection-url>
<driver>oracle</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
<flush-strategy>IdleConnections</flush-strategy>
</pool>
<security>
<user-name>USER</user-name>
<password>PASSWORD</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"/>
<check-valid-connection-sql>select 1 from dual</check-valid-connection-sql>
<background-validation>true</background-validation>
<stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleStaleConnectionChecker"/>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter"/>
</validation>
<timeout>
<blocking-timeout-millis>5000</blocking-timeout-millis>
<idle-timeout-minutes>5</idle-timeout-minutes>
</timeout>
</datasource>
<driver name="oracle" module="com.oracle">
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
module.xml
<?xml version=”1.0" ?><?xml version='1.0' encoding='UTF-8'?>
<module xmlns=”urn:jboss:module:1.3" name=”com.oracle”>
<resources>
<resource-root path=”ojdbc10.jar”/>
</resources>
<dependencies>
<module name=”javax.api”/>
<module name=”javax.transaction.api”/>
</dependencies>
</module>

I had this issue, and the only way I could solve it was to place the oracle driver in the keycloak/modules directory.
These did not work:
keycloak/modules/system/layers/keycloak/com/oracle It is here that is described in the KeyCloak documentation, and it worked for me for Postgres, but I could not get the oracle driver to load from here.
keycloak/modules/system/layers/base/com/oracle : Tried this out of desperation.
But this worked for me in:
keycloak/modules/com/oracle
keycloak/modules/com/oracle/main/module.xml
<?xml version='1.0' encoding='UTF-8'?>
<module xmlns="urn:jboss:module:1.1" name="com.oracle">
<resources>
<resource-root path="ojdbc8.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
And the ojdbc8.jar file was also in this directory.
NOTE: The name="com.oracle" has to match the path com/oracle in the module directory.
In the standalone.xml file, I added the following datasource.
<datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true">
<connection-url>jdbc:oracle:thin:#hostname:1521:SID</connection-url>
<driver>oraclejdbc</driver>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>20</max-pool-size>
</pool>
<security>
<user-name>user</user-name>
<password>password</password>
</security>
</datasource>
With the matching driver
<driver name="oraclejdbc" module="com.oracle">
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
NOTE:
the module="com.oracle" matches the path com/oracle.
the driver name="oraclejdbc" matches the <driver>oraclejdbc</driver> element.
Once working, I saws this in the log.
2021-05-31 14:46:17,376 INFO [org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory] (ServerService Thread Pool -- 60) Database info: {databaseUrl=jdbc:oracle:thin:#server:1521:SID, databaseUser=user, databaseProduct=Oracle Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.10.0.0.0, databaseDriver=Oracle JDBC driver 19.3.0.0.0}
But prior to it working I would see the following errors in the log (which I am including, incase people are googling the error message)
2021-05-31 14:47:12,049 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 50) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "oraclejdbc")
]) - failure description: "WFLYJCA0115: Module for driver [com.oracle] or one of it dependencies is missing: [com.oracle]"
Or this error
2021-05-31 14:47:14,962 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "KeycloakDS")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.oraclejdbc"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"org.wildfly.data-source.KeycloakDS is missing [jboss.jdbc-driver.oraclejdbc]",
"jboss.driver-demander.java:jboss/datasources/KeycloakDS is missing [jboss.jdbc-driver.oraclejdbc]"
]
}

Adde module via commandline.
module add --name=oracle.jdbc --resources=customization/ojdbc10.jar --dependencies=javax.transaction.api
Created under the following structure:
-keycloak
--modules
----oracle
------jdbc
--------main
----------module.xml
----------ojdbc10.jar

Related

Unable to use postgres with keycloak

I am trying to use postgres with keycloak. following Doc
$ ls keycloak-9.0.0/modules/system/layers/keycloak/org/postgresql/main
config.xml postgresql-42.2.10.jar
This is the config.xml file.
config.xml
<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.3" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.10.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
These are the changes that i have made in standalone.xml
standalone.xml
<datasources>
<datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://localhost:5432/test</connection-url>
<driver>postgresql</driver>
<pool>
<max-pool-size>20</max-pool-size>
</pool>
<security>
<user-name>postgres</user-name>
<password>StrongPassword</password>
</security>
</datasource>
<drivers>
<driver name="postgresql" module="org.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
<default-bindings context-service="java:jboss/ee/concurrency/context/default" datasource="java:jboss/datasources/KeycloakDS">
The error i am getting.
error
06:13:39,430 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 32) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "postgresql")
]) - failure description: "WFLYJCA0115: Module for driver [org.postgresql] or one of it dependencies is missing: [org.postgresql]"
How can i resolve this?
Can I suggest another way to configure this that is less likely to have an issue? I use the following to configure PostgreSQL and Keycloak and it has been working well. The key is to run this against a stopped Keycloak (using a fresh install). Save the below to something like setup-keycloak.cli:
embed-server --server-config=standalone.xml --std-out=echo
batch
#
# remove the default provided datasource
#
/subsystem=datasources/data-source=KeycloakDS/:remove
#
# add them
#
module add --name=org.postgres --resources=/path/to/postgresql-42.2.10.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=KeycloakDS/:add(connection-url=jdbc:postgresql://localhost:5432/keycloak_database,driver-name=postgres,jndi-name=java:jboss/datasources/KeycloakDS,initial-pool-size=4,max-pool-size=64,min-pool-size=4,password=keycloak_user,user-name=keycloak_pass)
run-batch
Then run this with $KEYCLOAK_HOME/bin/jboss.sh --file=setup-keycloak.cli. This removes the KeycloakDS datasource, adds the PostgreSQL module, and recreates the KeycloakDS datasource with your parameters. You can use this to reproduce the configuration any time as long as you have a local copy of the PostgreSQL JDBC driver.
I think your problem is that you named the settings config.xml and should be module.xml.
Second you have to download postgresql jar to that location:
curl -O https://jdbc.postgresql.org/download/postgresql-X.X.X.jar > /opt/keycloak/modules/system/layers/keycloak/org/postgresql/main
just replace the X.X.X with your version.
Then restart the server.
PS: you should use a vault for your password.
This works for me.
create PostgreSQL module.xml (not config.xml) inside base directory (keycloak-11.0.2/modules/system/layers/base/com/postgresql/)
update standalone.xml
<datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true"
statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
<connection-url>jdbc:postgresql://localhost:5432/keycloak</connection-url>
<driver>postgresql</driver>
<security>
<user-name>db-user</user-name>
<password>db-pass</password>
</security>
</datasource>
<drivers>
<driver name="postgresql" module="com.postgresql.h2">
<driver-class>org.postgresql.Driver</driver-class>
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
This works for me in standalone:
In file module.xml
<module xmlns="urn:jboss:module:1.3" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.23.jar" />
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
2.In file standalone.xml
<datasources>
<datasource jndi-name="java:jboss/datasources/KeycloakDS"
pool-name="KeycloakDS"
enabled="true"
use-java-context="true"
statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}" >
<connection-url>jdbc:postgresql://192.168.1.XX:5432/Your-DataBase</connection-url>
<driver>postgresql</driver>
<pool>
<max-pool-size>20</max-pool-size>
</pool>
<security>
<user-name>UserName</user-name>
<password>**********</password>
</security>
<statement>
<prepared-statement-cache-size>32</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
<drivers>
<driver name="postgresql" module="org.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
3.in file standalone.xml
<default-bindings
context-service="java:jboss/ee/concurrency/context/default"
datasource="java:jboss/datasources/KeycloakDS"
managed-executor-service="java:jboss/ee/concurrency/executor/default"
managed-scheduled-executor-service="java:jboss/ee/concurrency/scheduler/default"
managed-thread-factory="java:jboss/ee/concurrency/factory/default"/>
For those who came here from tutorials with Dockerized jboss/keycloak instance, you have built-in rdbms support without any configuration: https://hub.docker.com/r/jboss/keycloak/
docker run -p 8080:8080 -e KEYCLOAK_USER=kuser -e KEYCLOAK_PASSWORD=kpass -e DB_VENDOR=postgres -e DB_ADDR=host:port -e DB_DATABASE=postgres -e DB_USER=pguser -e DB_PASSWORD=pgpass jboss/keycloak:15.0.2

wildfly wont start because of new missing/unsatisfied dependencies

When I try to start my WildFly server, I got this error :
2018-11-17 21:29:55,203 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "org.postgresql")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [org.postgresql]"
ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "swap")
]) - failure description: {"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.driver-demander.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]",
"jboss.data-source.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]"
]}
2018-11-17 21:30:07,625 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "swap")
]) - failure description: {"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.driver-demander.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]",
"jboss.data-source.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]",
"jboss.data-source.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]"
]}
And my standalone.xml :
<datasources>
<datasource jndi-name="java:jboss/datasources/swap" pool-name="swap" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://127.0.0.1:5432/swap?useUnicode=yes&characterEncoding=UTF-8</connection-url>
<driver>org.postgresql</driver>
<security>
<user-name>postgres</user-name>
<password>postgres</password>
</security>
</datasource>
<drivers>
<driver name="org.postgresql" module="org.postgresql">
<driver-class>org.postgresql.Driver</driver-class>
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
</drivers>
</datasources>
My PostgreSQL module.xml :
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.5.jar"/>
</resources>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
What could be the problem? Please help and Thanks.
Your module.xml is invalid. A <dependencies> tag is missing. Try it with the following:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.5.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
EDIT:
The module.xml file and the postgresql-42.2.5.jar have to be in
C:\wildfly\wildfly-9.0.2.Final\modules\system\layers\base\org\postgresql\main.
It is also recommended to put your modules directly into
C:\wildfly\wildfly-9.0.2.Final\modules\.
So in your case C:\wildfly\wildfly-9.0.2.Final\modules\org\postgresql\main, that can be problem.
For reference, also have a look at the EAP7 Documentation and you should also think about using the jboss-cli.
For configuration of PostgresSQL for WildFly server, you should follow the following steps.
Step 1 : Adding PostgreSQL Module
Create new folder ${wildfly_home}/modules/system/layers/base/org/postgresql/main/ if not exist.
Download Latest Driver Jar via this link => https://jdbc.postgresql.org/download.html and put under the above folder.
Also in that new folder, Create module.xml and put the following config.
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.23.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
May be jar version need to update in resource-root.
Step 2 : Update DB configs from standalone.xml
Remove Existing <driver> config and add new config as follow.
<driver name="postgresql" module="org.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
Remove existing <datasource> config and add new config as follow.
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://127.0.0.1:5432/swap?useUnicode=yes&characterEncoding=UTF-8</connection-url>
<driver>postgresql</driver>
<security>
<user-name>postgres</user-name>
<password>postgres</password>
</security>
<pool>
<max-pool-size>20</max-pool-size>
</pool>
</datasource>
Modify default-bindings datasource name to PostgresDS from ExampleDS.
<default-bindings context-service="java:jboss/ee/concurrency/context/default" datasource="java:jboss/datasources/PostgresDS" ...
Make sure that you have created your swap database in PostgreSQL database server.
Now, run server and it will be fine.

JBoss : Not able to add datasouce

I am trying to add datasource for IBM DB2 database and it is showing below error
ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 2) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "DB2DS1")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.db2"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"org.wildfly.data-source.DB2DS1 is missing [jboss.jdbc-driver.db2]",
"jboss.driver-demander.java:/DB2DS1 is missing [jboss.jdbc-driver.db2]"
]
}
I have below configuration in module.xml which is placed along with database driver in EAP-7.1.0\modules\system\layers\base\com\ibm\db2\main location
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.5" name="com.ibm.db2">
<properties>
<property name="jboss.api" value="unsupported"/>
</properties>
<resources>
<resource-root path="db2jcc.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
Also I think I have successfully installed driver as module because I am seeing it's entry in standalone.xml like
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="db2" module="com.ibm.db2">
<datasource-class>com.ibm.db2.jcc.DB2Driver</datasource-class>
</driver>
</drivers>
What thing I am missing here ?.
To add datasource I am hitting below command from CLI
data-source add --name=DB2DS1--jndi-name=java:/DB2DS1--driver-name=db2 --connection-url=jdbc:db2://localhost:50000/sample
It was a silly mistake I did...
Below is the correct configuration that should be there in standalone.xml
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="db2" module="com.ibm.db2">
<driver-class>com.ibm.db2.jcc.DB2Driver</driver-class>
</driver>
</drivers>
For simplicity I have followed below steps to add db2 datasource
Created module.xml as mentioned in above question
Added database driver for datasource
/subsystem=datasources/jdbc-driver=ibmdb2:add(driver-name=ibmdb2,driver-module-name=com.ibm.db2,driver-class-name=com.ibm.db2.jcc.DB2Driver)
Added datasource to subsystem
data-source add --name=DB2_EFTDEVS1 --driver-name=ibmdb2 --driver-class=com.ibm.db2.jcc.DB2Driver --user-name=Administrator --password=Test#123 --connection-url=jdbc:db2://localhost:50000/sample --jndi-name="java:jboss/datasources/DB2_EFTDEVS1"

Wildfly 10 with Postgres 9.6.6 and Hibernate 5.2.12.final

I am trying to get a Java8EE application working on Wildfly10 and Postgres 9.6.6.
Somehow I allways bump into the error that the relation cannot be found.
My Postgres is running on localhost, default port. I am connecting with the user postgres and the correct password. The database (hbnac) has a schema with the same name.
Wildfly is configured to use the database and the “Test connection” is confirming a successful connection.
Using pgAdmin 4 I can also browse the database, see the schema, as well as the table group_member.
The config in Jboss looks as follow:
<datasource jta="false" jndi-name="java:jboss/datasources/hbnac" pool-name="hbnac" enabled="true" use-ccm="false">
<connection-url>jdbc:postgresql://localhost:5432/hbnac</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgres</driver>
<pool>
<min-pool-size>1</min-pool-size>
<initial-pool-size>1</initial-pool-size>
<max-pool-size>10</max-pool-size>
<flush-strategy>Gracefully</flush-strategy>
</pool>
<security>
<user-name>postgres</user-name>
<password>password</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
<background-validation>true</background-validation>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
</validation>
</datasource>
However, my application fails to select a record from the very same table, resulting in the following error:
Caused by: org.postgresql.util.PSQLException: ERROR: relation "group_member" does not exist
The configuration of my persistence.xml is doing a jndi lookup of the connection defined in Wildfly:
<persistence-unit name="hbnac">
<jta-data-source>java:jboss/datasources/hbnac</jta-data-source>
<class>hbnac.birthday.domain.groupmember.GroupMember</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect" />
<!--property name="hibernate.hbm2ddl.auto" value="validate"/-->
<!--property name="hibernate.default_schema" value="hbnac"/-->
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
And obviously, the jta-data-source is matching the working datasource in Wildfly. As you can see, I have experimented a bit with the validate (which fails for the same reason at startup) and with the schema name, which also does not make a difference.
The entity itsel is annoted:
#Entity
#Table(name = "group_member")
public class GroupMember extends AbstractEntity {
public final static String FACEBOOK_NAME_FIELD = "facebookName";
public final static String BIRTHDAY_FIELD = "birthday";
#Id
#GeneratedValue(strategy= GenerationType.IDENTITY)
private long id;
It has getters, setters, hashcode and equals methode for all fields available.
If I copy the query generated by hibernate into pgadmin it also works perfectly...
Any ideas left?
success to test connection, but even couldn't find table
that indicates ,perhaps schema setting is not defined correctly.
then, should put a currentSchema like this
<connection-url>jdbc:postgresql://localhost:5432/hbnac?currentSchema=hbnac</connection-url>
and if you use Hibernate to issue query should enable this comment outed code
<!--property name="hibernate.default_schema" value="hbnac"/-->
I found the error after many tries! It was caused by the configuration of the Postgres module in Wildfly itself.
What I had before:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-42.1.4.jar" />
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true" />
</dependencies>
and in the standalone.xml:
<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>
for the datasource itself:
<datasource jta="false" jndi-name="java:jboss/datasources/hbnac" pool-name="hbnac" enabled="true" use-ccm="false">
<connection-url>jdbc:postgresql://localhost:5432/hbnac</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgres</driver>
...
This configuration gave a successful connection but the error that a relation could not be found.
By replacing it with the following configuration, everything is working fine:
For the module.xml:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-42.1.4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
For the driver in the standalone.xml:
<driver name="postgresql" module="org.postgres">
<driver-class>org.postgresql.Driver</driver-class>
</driver>
And finally for the db connection:
<datasource jta="true" jndi-name="java:/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://localhost:5432/hbnac</connection-url>
<driver>postgresql</driver>
<security>
...

Wildfly 9 datasource spring jpa missing dependencies error on openshift

I am want to deploy an application with spring jpa using datasource from wildfly9, I think I have all configuration needed but I am getting an error.
What i have is
standalon.xml in subsystem
<datasource jndi-name="java:jboss/datasources/PostgreSQLDS"
jta="true" enabled="${postgresql.enabled}"
use-java-context="true"
pool-name="PostgreSQLDS"
use-ccm="true">
<connection-url>
jdbc:postgresql://${env.OPENSHIFT_POSTGRESQL_DB_HOST}:${env.OPENSHIFT_POSTGRESQL_DB_PORT}/${env.OPENSHIFT_APP_NAME}
</connection-url>
<driver>postgresql</driver>
<security>
<user-name>${env.OPENSHIFT_POSTGRESQL_DB_USERNAME}
</user-name>
<password>
${env.OPENSHIFT_POSTGRESQL_DB_PASSWORD}
</password>
</security>
<validation>
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<background-validation>true</background-validation>
<background-validation-millis>60000</background-validation-millis>
</validation>
<pool>
<flush-strategy>IdleConnections</flush-strategy>
</pool>
</datasource>
<drivers>
<driver name="postgresql" module="org.postgresql.jdbc">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
</drivers>
my spring.profile.xml has
<beans:bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<beans:property name="jndiName" value="java:jboss/datasources/PostgreSQLDS"/>
</beans:bean>
and the error i am getting is
[0m[31m08:57:40,995 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "ROOT.war")]) - failure description: {"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.persistenceunit.\"ROOT.war#my-jpa\".__FIRST_PHASE__ is missing [jboss.naming.context.java.\"\\n java:comp\".env.jdbc.\"PostgreSQLDS\\n \"]",
"jboss.persistenceunit.\"ROOT.war#my-jpa\" is missing [jboss.naming.context.java.\"\\n java:comp\".env.jdbc.\"PostgreSQLDS\\n \"]"
]}
I am not sure what i am doing bad, any help is welcome
Try this JNDI resource mapping with java:comp/env and you need datasource resource reference in your app using jboss-web.xml below.
<beans:bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<beans:property name="jndiName" value="java:comp/env/jdbc/PostgreSQLDS"/>
</beans:bean>
Add jboss-web.xml inside WEB-INF folder with this content
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<context-root>/myAppRoot</context-root>
<resource-ref>
<res-ref-name>jdbc/PostgreSQLDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:jboss/datasources/PostgreSQLDS</jndi-name>
</resource-ref>
</jboss-web>