如何在Wildfly 10上设置MariaDB JNDI?

时间:2016-10-05 07:48:43

标签: java tomcat wildfly jndi

我正在尝试将我的Tomcat Web服务移动到Wildfly 10.我认为它应该拖放到Wildfly的部署文件夹中,一切都应该没问题,但似乎不是那样。

这是我在standalone.xml中的MariaDB数据源定义:

<datasource jndi-name="java:jboss/MariaDBDS" pool-name="MariaDBDS">
    <connection-url>jdbc:mariadb://db_ip/db_name</connection-url>
    <driver>mariadb</driver>
    <security>
        <user-name>dbAcc</user-name>
        <password>dbPassword</password>
    </security>
    <validation>
        <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
        <validate-on-match>true</validate-on-match>
        <background-validation>false</background-validation>
        <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
    </validation>
    </datasource>
    <drivers>
        <driver name="mariadb" module="org.mariadb">
            <driver-class>org.mariadb.jdbc.Driver</driver-class>
            <xa-datasource-class>org.mariadb.jdbc.MariaDbDataSource</xa-datasource-class>
        </driver>
    </drivers>

然后我将mariadb-java-client-1.4.6.jar和我的WAR文件放入wildfly/standalone/deployments,启动Wildfly,并且出现错误消息:

07:05:21,137 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 60) WFLYUT0021: Registered web context: /MySV
07:05:21,143 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "MariaDBDS")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.mariadb"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
    "jboss.driver-demander.java:jboss/MariaDBDS is missing [jboss.jdbc-driver.mariadb]",
    "org.wildfly.data-source.MariaDBDS is missing [jboss.jdbc-driver.mariadb]"
]
}
07:05:21,148 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "MariaDBDS")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => [
    "jboss.jdbc-driver.mariadb",
    "jboss.jdbc-driver.mariadb"
],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
    "jboss.driver-demander.java:jboss/MariaDBDS is missing [jboss.jdbc-driver.mariadb]",
    "org.wildfly.data-source.MariaDBDS is missing [jboss.jdbc-driver.mariadb]",
    "org.wildfly.data-source.MariaDBDS is missing [jboss.jdbc-driver.mariadb]"
]
}

我不能让我的服务连接到DB,我错过了任何一步吗?

1 个答案:

答案 0 :(得分:1)

如果我查看您的配置,则将驱动程序设置为模块。因此,您将其创建为服务器中的模块,而不是将其部署为部署文件夹中的单独jar。

如果要设置驱动程序位于deployments文件夹中的数据源,可以执行以下操作:

<datasource jndi-name="java:jboss/MariaDBDS" pool-name="MariaDBDS">
    <connection-url>jdbc:mariadb://db_ip/db_name</connection-url>
    <driver>mariadb-java-client-1.4.6.jar</driver>
    <driver-class>org.mariadb.jdbc.Driver</driver-class>
    <security>
        <user-name>dbAcc</user-name>
        <password>dbPassword</password>
    </security>
    <validation>
        <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
        <validate-on-match>true</validate-on-match>
        <background-validation>false</background-validation>
        <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
    </validation>
</datasource>

不需要单独的驱动程序声明,它全部包含在数据源配置中。