How to configure Wildfly 10 to use MySQL

Follow these steps to configure MySQL in Wildfly 10

Step 1: Download MySQL connector jar from mysql downloads page.

Step 2: Go to modules\system\layers\base\com of your Wildfly home

Step 3: Create folder like mysql\main and go to mysql\main

Step 4: Place the downloaded connector jar in the main folder 

Step 5: Create a file named module.xml in the main folder and put the following content in it. Set the path variable so that it matches the name of the jar file.

<?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.39-bin.jar"/>             
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>

Step 6: Go to standalone\configuration directory of Wildfly home and open standalone.xml file

Step 7: Add a driver definition for MySQL by putting the following code inside datasources->drivers xml block

<driver name="mysql" module="com.mysql">
    <driver-class>com.mysql.jdbc.Driver</driver-class>
 </driver>

Step 8: Add a datasource definition inside datasources with the following code:

<datasource jndi-name="java:jboss/datasources/SchoolAppDS" pool-name="SchoolAppDS" enabled="true" use-java-context="true">
    <connection-url>jdbc:mysql://localhost/schooldbv3</connection-url>
    <driver>mysql</driver>
    <pool>
        <min-pool-size>2</min-pool-size>
        <max-pool-size>5</max-pool-size>
    </pool>
    <security>
        <user-name>root</user-name>
        <password>123456</password>
    </security>
</datasource>

Replace localhost, schooldbv3, SchoolAppDS with your DB server's host name or IP, name of your database and your desired name for defining datasource and connection pool. Also set min-pool-size and max-pool-size to values suitable for your need.

Comments

  1. Thats brilliant I love.Good job keep it up

    ReplyDelete
    Replies
    1. Thanks a lot for your comment. Feeling happy knowing that my small effort helped someone.

      Delete
  2. Thank's
    Good explication

    ReplyDelete
  3. It is possible install mysql module from WEB Console?

    ReplyDelete
  4. Hi!
    I am getting followong error while running wildfly

    ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
    ("subsystem" => "datasources"),
    ("data-source" => "Ontobrowser")
    ]) - failure description: {
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.com_mysql"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
    "jboss.driver-demander.java:jboss/datasources/Ontobrowser is missing [jboss.jdbc-driver.com_mysql]",
    "org.wildfly.data-source.Ontobrowser is missing [jboss.jdbc-driver.com_mysql]"

    ReplyDelete
    Replies
    1. Verify module.xml in main folder. Driver name and version should be correct.

      Delete

Post a Comment

Popular posts from this blog

Run tasks in background in Spring

Conditional field inclusion in Jackson and Spring Boot