我有一个客户端,一个服务器和一个数据库。客户端通过EJB远程接口与服务器通信。作为服务器-我使用Wildfly 8.2.0。作为数据库- 我使用MySQL。服务器通过JPA /休眠与MySQL通信。当我关闭MySQL服务器时,Wildfly当然会引发异常。但是,当我再次打开MySQL时- Wildfly仍然会抛出相同的错误。我必须关闭Wildfly,然后重新将Wildfly重新连接到数据库。
如何在Wildfly中设置自动重新连接?
我试图在连接URL中设置自动重新连接:jdbc:mysql://localhost/db?autoReconnect=true&useUnicode=yes&characterEncoding=UTF8并尝试将其添加到我使用的standalone- full.xml文件中,这一行:<check-valid-connection-sql>select 1</check-valid-connection- sql>,但是两种解决方案均不起作用。
jdbc:mysql://localhost/db?autoReconnect=true&useUnicode=yes&characterEncoding=UTF8
<check-valid-connection-sql>select 1</check-valid-connection- sql>
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;useUnicode=yes&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解决了此问题:
<validate-on-match>true</validate-on-match>