刺尾 2.6.0.Final "WFLYJCA0114: Failed to load datasource class: com.mysql.cj.jdbc.MysqlXADataSource"

Thorntail 2.6.0.Final "WFLYJCA0114: Failed to load datasource class: com.mysql.cj.jdbc.MysqlXADataSource"

我是第一次使用 Thorntail (2.6.0),将它连接到我的 Mysql Database (8.0.18)

时遇到问题

我得到以下异常

2019-12-22 17:43:08,832 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 48) WFLYCTL0013: Operation ("add") failed - address: ([
    ("subsystem" => "datasources"),
    ("jdbc-driver" => "mysql")
]) - failure description: "WFLYJCA0114: Failed to load datasource class: com.mysql.cj.jdbc.MysqlXADataSource"

随后出现此异常

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

我已经做了以下设置

我有 JAVA_HOME 应该是 Java 8 Zulu on a MacBook with Catalina

我有一个模块 ../src/main/resources/modules/com/mysql/main/module.xml,其中包含以下内容

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

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

我在../src/main/resources/META-INF/persistence.xml的Persistence.xml里面有这个

    <?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="SPU" transaction-type="JTA">

    <!-- The "Java-Transaction-API" datasource here refers to the datasource defined in /src/main/resources/project-defaults.yml. -->
    <jta-data-source>java:jboss/datasources/MainDS</jta-data-source>

    <!-- User and password defines in project-defaults.yml -->
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
        <property name="hibernate.connection.driver_class" value="com.mysql.cj.jdbc.Driver"/>
        <property name="hibernate.show_sql" value="false"/>
        <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
</persistence-unit>
        </persistence>

我的项目-defaults.yml在../src/main/resources/project-defaults.yml里面有这个

 thorntail:
  datasources:
    jdbc-drivers:
      mysql:
        driver-module-name: com.mysql
        driver-xa-datasource-class-name: com.mysql.cj.jdbc.MysqlXADataSource
    data-sources:
      MainDS:
        driver-name: mysql
        connection-url: jdbc:mysql://localhost:3306/Mysql
        user-name: ****
        password: ****

我的 pom 中有这个:

<dependency>
  <groupId>io.thorntail</groupId>
  <artifactId>datasources</artifactId>
</dependency>
<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>${version.mysql}</version>
</dependency>

我的数据库是运行,这应该不是问题。

我还在某处读到 WildFly 中有错误,停止了 thorntail 查找 com.mysql.cj.jdbc.MysqlXADataSource

感谢所有帮助我的人,我已经被这个问题困扰了一整天了。

我的目标是 Java-EE 服务器 (FatJar),后面有 JPAMySQL 数据库。

Thorntail 可以自动检测许多 JDBC 驱动程序,包括 MySQL。您不必创建 module.xml 文件,并且 thorntail.datasources.jdbc-drivers.mysql 部分配置也不是必需的。依赖 JDBC 驱动程序(你有)并定义数据源(你也有)就足够了。 driver-name 应该是 mysql,你也已经有了。

有关详细信息,请参阅 https://docs.thorntail.io/2.6.0.Final/#auto-detecting-jdbc-drivers_thorntail and https://docs.thorntail.io/2.6.0.Final/#_datasources