How to configure datasource in wildfly 10?

Problem resolved after move module.xml to wildfly-10.0.0.CR2\wildfly-10.0.0.CR2\modules\org\postgres\main


Below given is driver configuration and data source creation and how to make it globally visible so that all J2EE deployments can access the particular module if needed.

1. PostGreSQL Driver Configuration

Create directory structure as below inside the modules in wildfly-8.2.0.Final\modules directory and place the mentioned files and driver jar. Directory: wildfly-8.2.0.Final\modules\org\postgresql\main

File: module.xml

    <!--<?xml version="1.0" encoding="UTF-8"?>-->
    <module xmlns="urn:jboss:module:1.0" name="org.postgresql">
        <resources>
            <resource-root path="postgresql-9.4-1204.jdbc41.jar"/>
        </resources>
        <dependencies><module name="javax.api"/></dependencies>
    </module>

JAR : PostGreSQL Driver: postgresql-9.4-1204.jdbc41.jar

Note : Driver version can be your choice and please ensure to reflect that version name in module.xml file. Please note that the driver name="org.postgresql” mentioned in the module.xml file should be matching with the data source(s) configuration in the standalone.xml file.

Note: The PostGreSQL driver version should be compatible to the java version in the system. In this example, java is 1.7 & PostGreSQL driver used is postgresql-9.4-1204.jdbc41.jar.

2. Configuring the DataSources

Datasources are configured in the standalone.xml file in the WildFly 8.2.0.Final\standalone\configuration. As the first step configure the PostGreSQL driver reference in the standalone.xml file as below inside the tag

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

1. Add the datasource details:

Please add this inside tag

<datasource jndi-name="java:/db1" pool-name="db1" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://localhost:5432/dbname</connection-url>
<driver>postgresql</driver>
<security>
    <user-name>user_name</user-name>
    <password>password</password>
</security>
</datasource>

2.make the published drivers globally visible by adding to the section

Here it is:

<global-modules>
            <module name="org.postgresql" slot="main"/>
</global-modules>

Note : Global modules is a set of JBoss Modules that will be added as dependencies to the JBoss Module of every Java EE deployment. Such dependencies allows Java EE deployments to see the classes exported by the global modules. Refer : https://docs.jboss.org/author/display/WFLY8/Subsystem+configuration

Once configured the above, please start your WildFly instance.