Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure datasource in wildfly 10?

I am starting introduction with wildfly learning. I have downloaded distribution of server.
Now I am trying to configure datasource but I see following error:

Unexpected HTTP response: 500

Request
{
    "address" => [
        ("subsystem" => "datasources"),
        ("data-source" => "PostgreDataSource")
    ],
    "operation" => "test-connection-in-pool"
}

Response

Internal Server Error
{
    "outcome" => "failed",
    "failure-description" => "WFLYJCA0040: failed to invoke operation: WFLYJCA0042: failed to match pool. Check JndiName: java:jboss/datasources/PostgreDataSource",
    "rolled-back" => true
}

My steps:
1. Created folder wildfly-10.0.0.CR2\wildfly-10.0.0.CR2\modules\org\postgres\main and copy postgresql-9.0-801.jdbc4.jar from \.m2\repository\postgresql\postgresql\9.0-801.jdbc4 there.

2.Created module.xml(inside wildfly-10.0.0.CR2\wildfly-10.0.0.CR2\modules):

with following content:

<module xmlns="urn:jboss:module:1.0" name="org.postgres"> 
  <resources> 
    <resource-root path="postgresql-9.0-801.jdbc4.jar"/> 
  </resources> 
   <dependencies> 
     <module name="javax.api"/> 
     <module name="javax.transaction.api"/> 
   </dependencies> 
</module> 
  1. Modified standalone.xml(wildfly-10.0.0.CR2\wildfly-10.0.0.CR2\standalone\configuration) like this(sorry - I don't know how to copy xml that it can be visible for another users(full content visible here: http://collabedit.com/psk4a)):

Please help to understand what do I wrong?

enter image description here

like image 982
gstackoverflow Avatar asked Oct 12 '15 12:10

gstackoverflow


5 Answers

Although this topic is a bit old, I'd like to stress that the recommended way to install a datasource as a module is using the CLI 'module add' command which creates the full path for the module and the module.xml configuration file. This makes the whole process less error-prone.

module add --name=org.postgres --resources=[JDBC JAR FILE] --dependencies=javax.api,javax.transaction.api

Also, I see mentioned here the usage of global modules for datasource. This is not a common practice for JDBC drivers as global modules are meant to be used for shared libraries which are common to all applications and don't require maintenance. You might end up with an unconsistent datasource configuration if the Database is upgraded and you forget to update the JDBC Driver in your modules configuration.

Ref: How to configure a Datasource in WildFly

like image 61
Francesco Marchioni Avatar answered Sep 28 '22 10:09

Francesco Marchioni


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.

like image 31
Ajay Kumar Avatar answered Oct 31 '22 13:10

Ajay Kumar


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

like image 3
gstackoverflow Avatar answered Oct 31 '22 15:10

gstackoverflow


I am not 100% positive, but if I see some links around the net it may be caused by default pool settings. You might try by adding specific pool configuration settings to your datasource:

<datasource jndi-name="blabla"... >
  <pool>  
    <min-pool-size>1</min-pool-size>  
    <max-pool-size>20</max-pool-size>  
    <prefill>true</prefill>            
  </pool>  
</datasource>

I base that on this stackoverflow thread: WildFly jdbc connection with Oracle

where an answer links to this related JBoss forum thread: https://developer.jboss.org/thread/257721

The pool settings are mentioned in the Wildfly configuration documentation by the way. This is Wildfly 9, but I can't imagine things changed much in Wildfly 10: https://docs.jboss.org/author/display/WFLY9/DataSource+configuration

like image 1
Gimby Avatar answered Oct 31 '22 15:10

Gimby


I'd like to say that I solved the problem only by using wildfly admin console (http://localhost:9990/console/). Not so spartan solution, but it works. I only pointed the JDBC driver jar from external directory and after I created a datasource. No xml by hand and no modifying wildfly's directory structure. For java 8 + postgresql 9.5 I used postgresql-42.1.1.jar. I had problems befor only because I chose the wrong driver and database's name was wrong.

like image 1
gleitonfranco Avatar answered Oct 31 '22 14:10

gleitonfranco