Wildfly-Thorntail无法连接到MariaDB

时间:2019-02-16 20:15:10

标签: java mariadb thorntail

我需要将Wildfly-Thorntail从2.2升级到2.3,以解决与Maven 3.6的兼容性问题。在带有2.2的Maven 3.5下,该项目可以完美地构建和运行,但是在3.6下,它抱怨“执行io.thorntail:thorntail-maven-plugin时遇到API不兼容”。

将Thorntail更改为2.3,0(为简洁起见,在此处进行了硬编码),即

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.thorntail</groupId>
            <artifactId>bom-all</artifactId>
            <version>2.3.0.Final</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

...程序正确构建,但是现在我在程序启动过程中收到此错误:

2019-02-16 21:54:22,159 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 21) WFLYCTL0013: Operation ("add") failed - address: ([
    ("subsystem" => "datasources"),
    ("jdbc-driver" => "mysql")
]) - failure description: "WFLYJCA0114: Failed to load datasource class:     com.mysql.jdbc.jdbc2.optional.MysqlXADataSource"

几行:

21:54:23,482 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
   ("subsystem" => "datasources"),
   ("data-source" => "my_ds")
]) - failure description: {
    "WFLYCTL0412: Required services that are not installed:" =>  ["jboss.jdbc-driver.mysql"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "org.wildfly.data-source.my_ds is missing [jboss.jdbc-driver.mysql]",
        "jboss.driver-demander.java:jboss/datasources/my_ds is missing [jboss.jdbc-driver.mysql]"
    ] 
}

我的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/my_ds</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.MySQL5InnoDBDialect" />
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.show_sql" value="false"/>
    </properties>
  </persistence-unit>
</persistence>

...在我的POM中,定义了以下连接器:

<!-- The driver used to access MariaDB, automatically detected by Thorntail and registered -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.15</version>
</dependency>

由于对Wildfly-Thorntail的了解有限,所以从今天早上开始我一直被困。任何坚持将不胜感激。

1 个答案:

答案 0 :(得分:0)

在8.x版本(这就是您的专家所指出的)中,在MySQL Connector / J中实现java.sql.Driver的类的名称已从com.mysql.jdbc.Driver更改为com.mysql.cj.jdbc.Driver。旧类名称已被弃用。

或者因为您使用MariaDB服务器,所以相应的驱动程序是:

    driver-class-name: org.mariadb.jdbc.Driver
    xa-datasource-class-name: org.mariadb.jdbc.MariaDbDataSource

使用maven:

<dependency>
  <groupId>org.mariadb.jdbc</groupId>
  <artifactId>mariadb-java-client</artifactId>
  <version>2.4.0</version>
</dependency>