jakarta-eewildflymysql-connector

WildFly 31.0.0.Final datasource config fails with MySQL driver not found (as module) when launched from IntelliJ


I think I've done this dozens of times. Install a local WildFly, add a MySQL driver as module for WildFly to connect to a local DB instance. This is for WildFly 31.0.0.Final.

Here's the standalone.xml:

    <subsystem xmlns="urn:jboss:domain:datasources:7.1">
        <datasources>
            <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
                <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=${wildfly.h2.compatibility.mode:REGULAR}</connection-url>
                <driver>h2</driver>
                <security user-name="sa" password="sa"/>
            </datasource>
            <datasource jndi-name="java:jboss/datasources/BBStatsDS" pool-name="BBStatsDS">
                <connection-url>jdbc:mysql://localhost:3306/bbstats</connection-url>
                <driver>mysql</driver>
                <security user-name="root" password="yippieyahey"/>
            </datasource>
            <drivers>
                <driver name="h2" module="com.h2database.h2">
                    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                </driver>
                <driver name="mysql" module="com.mysql">
                    <driver-class>com.mysql.cj.jdbc.Driver</driver-class>
                    <xa-datasource-class>com.mysql.cj.jdbc.MysqlXADataSource</xa-datasource-class>
                </driver>
            </drivers>
        </datasources>
    </subsystem>

I installed the MySQL connector driver to WildFly under com/mysql/main:

enter image description here

module.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright The WildFly Authors
  ~ SPDX-License-Identifier: Apache-2.0
  -->
<module name="com.mysql" xmlns="urn:jboss:module:1.9">
    <resources>
        <resource-root path="mysql-connector-j-8.3.0.jar" />
    </resources>
    
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api "/>
    </dependencies>
</module>

I double-checked the driver in the admin console, which seems to be OK:

enter image description here

But when I launch the server (from IntelliJ), I get:

09:49:31,266 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
    ("subsystem" => "datasources"),
    ("data-source" => "BBStatsDS")
]) - failure description: {
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.mysql"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "service jboss.data-source.\"jboss.naming.context.java.jboss.datasources.BBStatsDS\" is missing [jboss.jdbc-driver.mysql]",
        "service jboss.driver-demander.java:jboss/datasources/BBStatsDS is missing [jboss.jdbc-driver.mysql]"
    ]
}
09:49:31,267 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
    ("subsystem" => "datasources"),
    ("data-source" => "BBStatsDS")
]) - failure description: {
    "WFLYCTL0412: Required services that are not installed:" => [
        "jboss.jdbc-driver.mysql",
        "jboss.jdbc-driver.mysql"
    ],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "service jboss.data-source.\"jboss.naming.context.java.jboss.datasources.BBStatsDS\" is missing [jboss.jdbc-driver.mysql]",
        "service jboss.driver-demander.java:jboss/datasources/BBStatsDS is missing [jboss.jdbc-driver.mysql]",
        "service jboss.data-source.\"jboss.naming.context.java.jboss.datasources.BBStatsDS\" is missing [jboss.jdbc-driver.mysql]"
    ]
}
09:49:31,272 INFO  [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0184:    New missing/unsatisfied dependencies:
      service jboss.jdbc-driver.mysql (missing) dependents: [service jboss.driver-demander.java:jboss/datasources/BBStatsDS, service jboss.data-source."jboss.naming.context.java.jboss.datasources.BBStatsDS"] 
WFLYCTL0448: 2 additional services are down due to their dependencies being missing or failed

EDIT:

Launching via standalone.sh doesn't make any difference from what I see:

enter image description here

Q:

What's wrong?

Is the server too new for the driver?


Solution

  • Instead of adding mysql driver as a module try adding to your pom file.

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.33</version>
    </dependency>
    

    I also suggest defining datasource with @DataSourceDefinition annotation that way your code will be Application server agnostic and it is lot easier if you work with Docker. configuration as code.

    import jakarta.annotation.sql.DataSourceDefinition;
    import jakarta.ejb.Singleton;
    
    @Singleton
    @DataSourceDefinition(
        name = "java:app/deneme2DS",
        className = "org.h2.jdbcx.JdbcDataSource",
        url = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1",
        user = "sa",
        password = "sa"
    )
    public class DataSourceConfig {
    
        // This class can be empty, as it only serves to define the DataSource
        // The DataSource will be automatically registered when this class is loaded
    
    }
    

    Finally remove the driver and datasource definitions from your standalone.xml and also remove the MySQL driver JAR from the modules dir.