0 Replies Latest reply on Feb 24, 2020 2:59 AM by patrickhub

    Mysql Driver class com.mysql.jdbc.Driver is not a valid javax.sql.DataSource implementation from wildfly

    patrickhub

      maybe my setup is quite special, but I do have issues when I define a JDBC Datasource for Java EE container in my web.xml file.

      I configured my Datasource in my web.xml as follow:

      ```

      <data-source>
        
      <name>java:app/myapp/DS</name>
        
      <class-name>com.mysql.jdbc.Driver</class-name>
        
      <url>jdbc:mysql://localhost:3306/database?useSSL=false&amp;allowPublicKeyRetrieval=true</url>
        
      <user>foo</user>
        
      <password>pass</password>
        
      <transactional>true</transactional>
        
      <isolation-level>TRANSACTION_READ_COMMITTED</isolation-level>
        
      <initial-pool-size>2</initial-pool-size>
        
      <max-pool-size>10</max-pool-size>
        
      <min-pool-size>5</min-pool-size>
        
      <max-statements>0</max-statements>
        
      </data-source>

      ```

       

      After I use datasource's name as my jta-data-source in my persistence file as follow:

       

      ```

      <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
        
      <persistence-unit name="java-rs-with-hibernate" transaction-type="JTA">
        
      <jta-data-source>java:app/myapp/DS</jta-data-source>
        
      <class>com.patrickhub.ch.java_rs_with_hibernate.domain.Product</class>
        
      <properties>

        
      <property name="javax.persistence.schema-generation.database.action" value="none"/>
        
      <property name="javax.persistence.schema-generation.scripts.action" value="none"/>
        
      </properties>
        
      </persistence-unit>
      </persistence>

      ```

       

      And in my code I used the EntityManager to make request to the database.

      But when I deploy it to wildfly 18.0.1, I get the following errors:

       

      ```

      at org.jboss.as.connector@18.0.1.Final//org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService.start(AbstractDataSourceService.java:174)
        at org
      .jboss.msc@1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
        at org
      .jboss.msc@1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
        at org
      .jboss.msc@1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
        at org
      .jboss.threads@2.3.3.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
        at org
      .jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
        at org
      .jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
        at org
      .jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1363)
        at java
      .base/java.lang.Thread.run(Thread.java:834)
      Caused
      by: org.jboss.jca.deployers.common.DeployException: WFLYJCA0030: unable to deploy
        at org
      .jboss.as.connector@18.0.1.Final//org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService$AS7DataSourceDeployer.deploy(AbstractDataSourceService.java:376)
        at org
      .jboss.as.connector@18.0.1.Final//org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService.start(AbstractDataSourceService.java:160)
        
      ... 8 more
      Caused
      by: org.jboss.as.controller.OperationFailedException: WFLYJCA0117: com.mysql.jdbc.Driver is not a valid javax.sql.DataSource implementation [ "WFLYJCA0117: com.mysql.jdbc.Driver is not a valid javax.sql.DataSource implementation" ]
        
      ... 10 more

      ```

      I think that if I replace com.mysql.jdbc.Driver with com.mysql.jc.jdbc.Driver, it will deploy successfully but I still have the same problem and the same message error.

      I don't know if I miss something on how to define a mysql JDBC datasource in web.xml file. but I think it is correct.

      Please can someone help me.