WildFly 部署因“无法构建 Hibernate SessionFactory”而失败 - 如何自动重试?

WildFly 部署因“无法构建 Hibernate SessionFactory”而失败 - 如何自动重试?

在客户的环境中,更新计划于夜间在多台服务器上运行,每次发生这种情况时,我们的 WildFly 应用程序都无法恢复,直到我重新启动应用程序服务器本身,因为在启动期间初始化 PersistenceUnit 时无法建立数据库连接(standalone-full.xml,作为 Windows 服务安装):

[由于省略了数据库连接,因此此时数据库连接基本上无法启动]

2024-03-26 01:51:00,009 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 46) WFLYSRV0010: Deployed "no.war" (runtime-name : "no.war")
2024-03-26 01:51:00,013 INFO  [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0186:   Services which failed to start:      service jboss.persistenceunit."no.war#xxxPU": jakarta.persistence.PersistenceException: [PersistenceUnit: xxxPU] Unable to build Hibernate SessionFactory
WFLYCTL0448: 170 additional services are down due to their dependencies being missing or failed

数据源定义:

            <datasource jta="false" jndi-name="java:jboss/datasources/xxx" pool-name="xxx">
                <connection-url>jdbc:sqlserver://xxx.xxx.de\INSTANCE;DatabaseName=xxx;encrypt=false</connection-url>
                <driver>mssql</driver>
                <security>
                    <user-name>CENSORED</user-name>
                    <password>CENSORED</password>
                </security>
                <validation>
                    <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker"/>
                </validation>
            </datasource>

而 persistence.xml 如下所示:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
   <persistence-unit name="xxxPU">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
      <jta-data-source>java:jboss/datasources/xxx</jta-data-source>
      <properties>
         <property name="hibernate.hbm2ddl.auto" value="validate"/>
         <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
         <property name="hibernate.jdbc.time_zone" value="Europe/Berlin"/>
      </properties>
   </persistence-unit>
</persistence>

虽然我可以理解这可能是期望的结果,但我个人不希望服务器一直处于这种失败状态直到重新启动。如果任何子系统的启动失败,是否有任何合理的方法可以配置 WildFly 以定期重试部署?

相关内容