You are on page 1of 6

2/5/2020 How to configure Datasource in WildFly

How to configure Datasource in WildFly


(https://cleanprogr
June 5, 2018
ammer.net/)
Monzurul Haque Shimul (https://cleanprogrammer.net/author/shimul/)

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy withRecaptcha
it.
Privacy -
OK No Read more (https://cleanprogrammer.net/privacy-policy/)
protected

https://cleanprogrammer.net/how-to-configure-datasource-in-wildfly/ 1/6
2/5/2020 How to configure Datasource in WildFly

WildFly is a free, open source & cross platform application server (formely known as Jboss AS or Jboss). It is
written in java programming language & currently it is being maintained, developed by Redhat. The most
notable features of WildFly are:

Fast Startup,

Small Footprint,
Modular
We use cookies toDesign,
ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy withRecaptcha
it.
Privacy -
Unified Configuration and
OK Management
No Read more (https://cleanprogrammer.net/privacy-policy/)
protected

https://cleanprogrammer.net/how-to-configure-datasource-in-wildfly/ 2/6
2/5/2020 How to configure Datasource in WildFly

And of course Java EE! In the previous post (https://cleanprogrammer.net/2018/06/05/how-to-add-oracle-jdbc-


driver-in-wildfly/) we already add oracle jdbc driver in wildfly. In this post, we are going to configure datasource
in WildFly. You can configure both non-xa datasource and xa-datasource using the management console ui from
your browser accessing http://localhost:9990/console, But in this post we will configure the datasource using
jboss-cli, the command line interface to configure WildFly.

Add Non-XA Datasource using jboss-cli


Lets go to the installation directory of your WildFly and connect to cli:

$ cd $JBOSS_HOME
$ ./bin/jboss-cli.sh --connect

Now we are connected to the running WildFly instance. To add a new datasource (oracle datasource in this
example) simply run:

l-size="25", max-pool-size="50", min-pool-size="20",connection-url="jdbc:oracle:thin:@localhost:1521/oradb")

You should see a success message if everything went well:

{"outcome" => "success"}

Here is another way to add datasource from jboss-cli.

[standalone@localhost:9990 /] data-source add --name=testDS --driver-name="oracle" --jndi-name="java:/jdbc/t

This will add following xml in standalone.xml or standalone-full.xml whichever you are using.

<datasource jndi-name="java:/jdbc/test" pool-name="testDS">


We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy withRecaptcha
<connection-url>jdbc:oracle:thin:@localhost:1521/oradb</connection-url> it.
<driver>oracle</driver> Privacy -
OK No Read more (https://cleanprogrammer.net/privacy-policy/)
protected
<pool>

https://cleanprogrammer.net/how-to-configure-datasource-in-wildfly/ 3/6
2/5/2020 How to configure Datasource in WildFly

<min-pool-size>20</min-pool-size>
<initial-pool-size>25</initial-pool-size>
<max-pool-size>50</max-pool-size>
</pool>
<security>
<user-name>user</user-name>
<password>pass</password>
</security>
</datasource>

Add XA-Datasource using jboss-cli


To add a new xa-datasource (oracle xa-datasource in this example) simply run:

[standalone@localhost:9990 /] xa-data-source add --name=testDS --allow-multiple-users=false --connectable=tr

This will add following xml in standalone.xml or standalone-full.xml whichever you are using.

<xa-datasource jndi-name="java:/jdbc/test" pool-name="testDS" enabled="true" use-java-context="true" use-ccm


<xa-datasource-property
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy withRecaptcha
name="URL"> it.
jdbc:oracle:thin:@localhost:1521/oradb Privacy -
OK No Read more (https://cleanprogrammer.net/privacy-policy/)
protected
</xa-datasource-property>

https://cleanprogrammer.net/how-to-configure-datasource-in-wildfly/ 4/6
2/5/2020 How to configure Datasource in WildFly

<driver>oracle</driver>
<xa-pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>20</max-pool-size>
<prefill>true</prefill>
<allow-multiple-users>false</allow-multiple-users>
<interleaving>false</interleaving>
<no-tx-separate-pools>false</no-tx-separate-pools>
<pad-xid>false</pad-xid>
<wrap-xa-resource>true</wrap-xa-resource>
</xa-pool>
<security>
<user-name>user</user-name>
<password>pass</password>
</security>
</xa-datasource>

Note that the data-source add and xa-data-source add examples above are not minimal in the sense of specifying

the required arguments only, they also include optional arguments you’ll most likely want to specify. For a list of
all the arguments run:

[standalone@localhost:9990 /] data-source add --help

or,

[standalone@localhost:9990 /] xa-data-source add --help

Now, let’s verify that everything is set up correctly by running

[standalone@localhost:9990 /] /subsystem=datasources:read-resource

And the output will be:

{
"outcome"
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy withRecaptcha
=> "success", it.
"result" => { Privacy -
OK No Read more (https://cleanprogrammer.net/privacy-policy/)
"data-source" => {"ExampleDS" => undefined},
protected

https://cleanprogrammer.net/how-to-configure-datasource-in-wildfly/ 5/6
2/5/2020 How to configure Datasource in WildFly

"jdbc-driver" => {
"h2" => undefined,
"oracle" => undefined
},
"xa-data-source" => {"testDS" => undefined}
}
}

Finally, make sure the connection can be established:

[standalone@localhost:9990 /] data-source test-connection-in-pool --name=testDS

If connection is successful, you will get true as return.

Note that, if you want to add datasource manually by editing the configuration xml filestandalone.xml or
standalone-full.xml whichever you are using, add the xml above in the `<datasources></datasources>` section.

Restart WildFly to take e ect.

That’s all for now.

Related Posts

(https://cleanprogrammer.net/making- (https://cleanprogrammer.net/improving- (https://cleanprogrammer.net/deploy-


get-request-with-body-using-spring- the-performance-of-wildfly-application- applications-to-oracle-weblogic-
resttemplate/) server-to-handle-concurrency/) server-using-weblogic-maven-plugin/)

Making a GET request with request Improving the performance of WildFly Deploy applications to Oracle
body using Spring RestTemplate application server to handle concurrency Weblogic Server using weblogic
(https://cleanprogrammer.net/making- (https://cleanprogrammer.net/improving- maven plugin
get-request-with-body-using-spring- the-performance-of-wildfly-application- (https://cleanprogrammer.net/deploy-
resttemplate/) server-to-handle-concurrency/) applications-to-oracle-weblogic-
server-using-weblogic-maven-plugin/)

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy withRecaptcha
it.
Privacy -
OK No Read more (https://cleanprogrammer.net/privacy-policy/)
protected

https://cleanprogrammer.net/how-to-configure-datasource-in-wildfly/ 6/6

You might also like