我正在尝试在Wildfly服务器关闭时对数据库执行一些更新。
不幸的是,在取消部署应用程序之前,似乎我正在关闭用于更新数据库的数据源......
以下是相关代码:
@PreDestroy
public void shutdown()
{
logger.debug("|||||||||||||||||||||||||||||||| Closing GatewayDAO");
System.out.println("Closing GatewayDAO ");
Session session = getSession();
Query query = session.createQuery("UPDATE Gateway gw SET gw.status = 0, gw.lastActivity = NOW()");
query.executeUpdate();
}
如您所见,我使用Spring destroy detection。
在Wildfly控制台中:
[...]
[WF] 11:58:22,794 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) WFLYJCA0010: Unbound data source [java:jboss/datasources/RfBerry]
[...]
[WF] 11:58:23,500 INFO [stdout] (ServerService Thread Pool -- 271) Closing GatewayDAO
[WF] 11:58:23,550 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (ServerService Thread Pool -- 271) SQL Error: 0, SQLState: null
[WF] 11:58:23,550 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (ServerService Thread Pool -- 271) javax.resource.ResourceException: IJ000470: You are trying to use a connection factory that has been shut down: java:jboss/datasources/RfBerry
[WF] 11:58:23,556 WARN [org.springframework.context.annotation.CommonAnnotationBeanPostProcessor] (ServerService Thread Pool -- 271) Invocation of destroy method failed on bean with name 'gatewayDAOImpl': org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
我不知道在应用程序取消部署后是否有可能告诉wildfly关闭数据源。
注意:当我取消部署应用程序并让服务器保持打开状态时,代码可以正常工作。
答案 0 :(得分:0)
您也可以尝试使用@DependsOn("datasource")
。