Thorntail 2.6.0.Final“ WFLYJCA0114:无法加载数据源类:com.mysql.cj.jdbc.MysqlXADataSource”

时间:2019-12-22 11:26:45

标签: java hibernate thorntail

我第一次使用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应该是带有Catalina的MacBook上的Java 8 Zulu

我有一个模块../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>

我在../src/main/resources/project-defaults.yml中的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中存在错误,从而阻止了寻找com.mysql.cj.jdbc.MysqlXADataSource的棘手问题。

感谢所有试图帮助我的人,我已经整天都遇到了这个问题。

我的目标是一个Java-EE服务器(FatJar),其后面有JPA和一个MySQL数据库。

1 个答案:

答案 0 :(得分:0)

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_thorntailhttps://docs.thorntail.io/2.6.0.Final/#_datasources