Wildfly 和自动重新连接到数据库 [英] Wildfly and auto reconnect to the database

查看:25
本文介绍了Wildfly 和自动重新连接到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户端、一个服务器和一个数据库.客户端通过 EJB 远程接口与服务器通信.作为服务器 - 我使用 Wildfly 8.2.0.作为数据库 - 我使用 MySQL.服务器通过 JPA/Hibernate 与 MySQL 通信.当我关闭 MySQL 服务器时 - 当然,Wildfly 会抛出异常.但是当我再次打开 MySQL 时 - Wildfly 仍然抛出相同的 ERROR.我必须关闭 Wildfly 并将其关闭,以便 Wildfly 重新连接到数据库.

I've got a client, a server and a database. The client communicates with the server via a EJB remote interfaces. As the server - I use a Wildfly 8.2.0. As the database - I use a MySQL. The server communicates with the MySQL via a JPA/Hibernate. When I turn off the MySQL server - the Wildfly throws an exception, of course. But when I turn on the MySQL again - the Wildfly still throws the same ERROR. I've to turn off the Wildfly and turn it back that the Wildfly reconnect to the database.

Wildfly 如何设置自动重连?

How to set auto reconnect in the Wildfly?

我尝试在连接 URL 中设置自动重新连接:jdbc:mysql://localhost/db?autoReconnect=true&amp;useUnicode=yes&amp;characterEncoding=UTF8 我试图添加到我使用的 standalone-full.xml 文件中,这一行:<check-valid-connection-sql>select 1</check-valid-connection-sql>,但两种解决方案都没有不行.

I tried to set auto reconnect in a connection URL: jdbc:mysql://localhost/db?autoReconnect=true&amp;useUnicode=yes&amp;characterEncoding=UTF8 and i tried to add to the standalone-full.xml file which i use, this line: <check-valid-connection-sql>select 1</check-valid-connection-sql>, but both solutions don't work.

standalone-full.xml:

standalone-full.xml:

<!-- ... -->
<datasource jta="true" jndi-name="java:jboss/datasources/MySQLDS" pool-name="MySQLDS" enabled="true" use-ccm="true">
    <connection-url>jdbc:mysql://localhost/db?autoReconnect=true&amp;amp;useUnicode=yes&amp;amp;characterEncoding=UTF8</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <driver>mysqlDriver</driver>
    <security>
        <user-name>user</user-name>
        <password>***</password>
    </security>
    <validation>
        <check-valid-connection-sql>select 1</check-valid-connection-sql>
        <validate-on-match>false</validate-on-match>
        <background-validation>false</background-validation>
    </validation>
    <timeout>
        <set-tx-query-timeout>false</set-tx-query-timeout>
        <blocking-timeout-millis>0</blocking-timeout-millis>
        <idle-timeout-minutes>0</idle-timeout-minutes>
        <query-timeout>0</query-timeout>
        <use-try-lock>0</use-try-lock>
        <allocation-retry>0</allocation-retry>
        <allocation-retry-wait-millis>0</allocation-retry-wait-millis>
    </timeout>
    <statement>
        <share-prepared-statements>false</share-prepared-statements>
    </statement>
</datasource>
<drivers>
    <driver name="mysqlDriver" module="com.mysql">
        <xa-datasource-class>com.mysql.jdbc.Driver</xa-datasource-class>
    </driver>
</drivers>
<!-- ... -->

推荐答案

我通过将我的 standalone-full.xml 文件中的 validate-on-match 值更改为 true 解决了这个问题:

I solved this problem by changing the validate-on-match value to true in my standalone-full.xml file:

true

这篇关于Wildfly 和自动重新连接到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆