Wildfly 10 failing to load MySQL XA driver on startup

I have a web application I am deploying in wildfly-10.0.0. It requires a mysql xa driver. I have the following error:

2015-10-13 12:25:37,979 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([ ("subsystem" => "datasources"), ("jdbc-driver" => "com.mysql") ]) - failure description: "WFLYJCA0041: Failed to load module for driver [com.mysql]"

The modules directory is as follows:

 Directory of C:\Users\rball\Documents\Dev\WildFly\wildfly-10.0.0.CR1\modules\sy
stem\layers\base\com\mysql\main

10/13/2015  11:32 AM    <DIR>          .
10/13/2015  11:32 AM    <DIR>          ..
10/13/2015  12:25 PM             1,575 module.xml
03/17/2015  05:21 AM           968,670 mysql-connector-java-5.1.35-bin.jar

The module.xml file is:

   <?xml version="1.0" encoding="UTF-8"?>    

<module xmlns="urn:jboss:module:1.1" name="com.mysql">  
  <resources>  
    <resource-root path="mysql-connector-java-5.1.35-bin.jar"/>  
  </resources>  
  <dependencies>  
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>      
  </dependencies>  
</module>  

I added the driver and datasource to the datasources section of standalone.xml:

<xa-datasource jndi-name="java:/jdbc/MyXaDS" pool-name="MyXaDSPool" enabled="true" use-ccm="false">
                <xa-datasource-property name="URL">
                    jdbc:mysql://localhost:3306/temp?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8
                </xa-datasource-property>
                <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                <driver>com.mysql</driver>
                <xa-pool>
                    <min-pool-size>10</min-pool-size>
                    <max-pool-size>20</max-pool-size>
                    <is-same-rm-override>false</is-same-rm-override>
                    <interleaving>false</interleaving>
                    <pad-xid>false</pad-xid>
                    <wrap-xa-resource>false</wrap-xa-resource>
                </xa-pool>
                <security>
                    <user-name>root</user-name>
                    <password>password</password>
                </security>
                <validation>
                    <validate-on-match>false</validate-on-match>
                    <background-validation>false</background-validation>
                    <background-validation-millis>1000</background-validation-millis>
                </validation>
                <statement>
                    <prepared-statement-cache-size>0</prepared-statement-cache-size>
                    <share-prepared-statements>false</share-prepared-statements>
                </statement>
            </xa-datasource>
            <drivers>
                <driver name="com.mysql" module="com.mysql">
                    <driver-class>com.mysql.jdbc.Driver</driver-class>
                    <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                </driver>
            </drivers>

Solution 1:

The error you get means that wildfly expects a module called com.mysql but it doesn't exist or it isn't registered under that name.

You are missing one step, which is registering the datasource jdbc driver. The first step of course being adding the mysql-connector-java-5.1.35-bin.jar file and module.xml file in WILDFLY_HOME\modules\system\layers\base\com\mysql\main.

To get rid of your error, stop wildfly, delete the the driver declaration in your standalone.xml by removing these lines; We'll let the /subsystem command create this entry.

<driver name="com.mysql" module="com.mysql">
     <driver-class>com.mysql.jdbc.Driver</driver-class>
     <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>

Open your command prompt and navigate to WILDFLY_HOME\bin\ and run the following commands.

  1. Connect to jboss cli by running : jboss-cli.bat --connect . In case your management console is running on a different port say , localhost:9991, use jboss-cli.bat --connect --controller=127.0.0.1:9991

  2. Then register the jdbc-driver with the following command

    /subsystem=datasources/jdbc-driver=com.mysql:add(driver-name=com.mysql,driver-module-name=com.mysql,driver-xa-datasource-class-name=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource)

You should get the response {"outcome" => "success"} if this was successful. From there, reload your server and you should get rid of that error.

I got pointers from This link

Solution 2:

I'm not really sure what the issue could be. The message isn't very informative.

That said the following add-mysql.cli script worked for me.

module add --name=com.mysql --resources=~/Downloads/mysql-connector-java-5.1.37/mysql-connector-java-5.1.37-bin.jar --dependencies=javax.api,javax.transaction.api

batch
/subsystem=datasources/jdbc-driver=com.mysql:add(driver-name=com.mysql, driver-module-name=com.mysql, driver-xa-datasource-class-name=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource)
/subsystem=datasources/xa-data-source=mysql:add(driver-name=com.mysql, jndi-name="java:/jdbc/MySQLXA", enabled=true)
/subsystem=datasources/xa-data-source=mysql/xa-datasource-properties=URL:add(value="jdbc:mysql://localhost:3306/temp?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8")
run-batch

I didn't write all the properties defined in your data source configuration, but this did work.

Solution 3:

WildFly 10 has some change in jca caused CLI create xa ds have some issue. https://issues.jboss.org/browse/WFLY-6773 https://issues.jboss.org/browse/WFLY-6789 https://issues.jboss.org/browse/WFLY-6774

But create xa datasouces use below commands works

xa-data-source add --name=MariaDBXADS --driver-name=mariadb-xa --jndi-name=java:jboss/datasources/MariaDBXADS --user-name=jdv_user --password=jdv_pass --use-java-context=true --xa-datasource-properties=[DatabaseName=>products, PortNumber=>3306, ServerName=>localhost]

Solution 4:

WILDFLY 10 using MySQL 5.7

Follow these steps: comment or delete exampleds in standalone.xml

into jboss-cli.bat --connect

After execute command:

[standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=mysql:add(driver-name=mysql,driver-module-name=com.mysql,driver-xa-datasource-class-name=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource)

should be ok.

This modified standalone.xml, then add:

<datasources>
  <!-- 
    <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
    <connection-

    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
      <driver>h2</driver>
      <security>
          <user-name>sa</user-name>
          <password>sa</password>
      </security>
    </datasource> 
  -->
  <datasource jndi-name="java:/mysql" pool-name="mysqlDS" enabled="true" use-java-context="true">
  <connection-url>jdbc:mysql://localhost:3306/wildfly</connection-url>
  <driver>mysql</driver>
    <security>
        <user-name>root</user-name>
        <password>jdfoxito10</password>
    </security>
  </datasource>
  <drivers>
    <driver name="mysql" module="com.mysql">
      <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
    </driver>
  </drivers>
</datasources>

should look like!

and module.xml put in

\java\server\wildfly-10.1.0.Final\modules\system\layers\base\com\mysql\main

mysql-connector-java-5.1.40-bin.jar (come installer mysql-installer-community-5.7.15.0.msi) module.xml

and content from module.xml like:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.40-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>

and ready, JAVA_HOME should be ok