in DevOps

org.jboss.msc.service.DuplicateServiceException: Service jboss.jdbc-driver.com_mysql is already registered

Environment

  • JBoss version 7.x
  • MySQL JDBCdriver
    • 5.1.30 and up

Issue

  • Using the CLI to register the mysql driver, we get an error.
  • Using the jar installer and adding the mysql driver during install, we get an error.
10:15:02,335 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 25) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
10:15:02,344 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 25) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.fabric.jdbc.FabricMySQLDriver (version 5.1)
10:15:02,346 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 25) JBAS014612: Operation ("add") failed - address: ([
    ("subsystem" => "datasources"),
    ("jdbc-driver" => "mysql")
]): org.jboss.msc.service.DuplicateServiceException: Service jboss.jdbc-driver.mysql is already registered
        at org.jboss.msc.service.ServiceRegistrationImpl.setInstance(ServiceRegistrationImpl.java:154) [jboss-msc.jar:1.0.4.GA-redhat-1]
...
  • We’re trying to create a new JDBC dataSource using cli command and we’re getting this error :
{
    "outcome" => "failed",
    "failure-description" => "JBAS014749: Manejador de operaciones fallido: Service jboss.jdbc-driver.XYZDriver is already registered",
    "rolled-back" => true
}

Resolution

  • This is fixed in WFLY-3218 by only registering the first driver. Any second driver class needs to be specifically set.
  • For the current EAP 6.x versions, setting the driver class is accepted as the solution. There are no plans to backport.
  • When adding the driver using the CLI, one needs to specify the driver class name (prefix with the correct profile for domain mode)
/subsystem=datasources/jdbc-driver=mysql:add(driver-module-name=com.mysql.jdbc,driver-xa-datasource-class-name=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource,driver-name=mysql,driver-class-name=com.mysql.jdbc.Driver)
  • Add this line to the “drivers” section in the subsystem “datasources” in standalone.xml.

    <driver-class>com.mysql.jdbc.Driver</driver-class>

    This results in the following xml snippet:

<subsystem xmlns="urn:jboss:domain:datasources:1.1">
  <datasources>
...
    <drivers>
       <driver name="mysql" module="com.mysql.jdbc">
         <driver-class>com.mysql.jdbc.Driver</driver-class>
         <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
       </driver>
...

Root Cause

  • The MySQL driver version 5.1.30 now has two driver classes registered in META-INF/services/java.sql.Driver
com.mysql.jdbc.Driver
com.mysql.fabric.jdbc.FabricMySQLDriver

The JDBC 4 specifications in section “9.2.1 Loading a driver that implements java.sql.Driver” does not explicitly state that more then one entry is allowed or disallowed.