Server
How to create a XA datasource in Wildfly 10…
I wanted to use mysql XA-Datasource to connect mysql datasources using the Wildfly 10 server. XA Datasources are better as it can span multiple resources.
Create the folder structure as /modules/system/layers/base/com/sql/mysql/main
Then create a file as module.xml in the main folder containing following data
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.sql.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.41-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.servlet.api" optional="true"/>
<module name="javax.validation.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Then copy the MySQL JDBC connector to the folder. The latest version that I had was mysql-connector-java-5.1.41-bin.jar. Change the name in module.xml accordingly.
Download: https://dev.mysql.com/downloads/connector/j/
(note: modify the xml resource-root according to the latest version of the connector jar )
Then go to the standalone/configuration folder and edit standalone.xml. Include following in the datasource part of the xml.
<datasources>
<xa-datasource jndi-name="java:jboss/datasources/madeinsl" pool-name="madeinsl" enabled="true" use-java-context="true">
<xa-datasource-property name="ServerName">
localhost
</xa-datasource-property>
<xa-datasource-property name="DatabaseName">
dbname
</xa-datasource-property>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>password</password>
</security>
<statement>
<prepared-statement-cache-size>100</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</xa-datasource>
<drivers>
<driver name="mysql" module="com.sql.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
Then test connection after login to the admin console. Then create a Datasource using the MySQL xa driver or use the Datasource properties that I have included in the xml.




