hibernate - Grails 2.3.11 错误 pool.ConnectionPool - 无法创建池的初始连接
问题描述
2018-04-19 20:57:38,504 [localhost-startStop-1] ERROR pool.ConnectionPool - Unable to create initial connections of pool.
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host MY-PC, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
我在启动时收到此错误三次。我想这是因为 Grails 在启动时尝试连接数据库三次,基于Burt Beckwith 的 No Fluff Just Stuff 在 Grails 中的延迟 SessionFactory 创建
在三个错误提示之后,Grails 在创建 bean(transactionManager、transactionManagerPostProcessor 等)时继续失败。
根据我的理解,这里的问题是池的创建。我假设 Hibernate 在 Grails 上处理这个问题。由于数据库仍未联机,因此无法创建池。
为了让您了解问题的背景,Grails 应用程序正在连接到数据库。数据库和 Grails 服务器位于不同的服务器上。两台服务器同时重启。然后 Grails 应用程序在数据库服务器之前首先在线的服务器。这会导致提到的错误,因为 Grails 应用程序尝试连接到尚未在线的数据库。
有没有办法配置 Grails 在创建池时发生错误或异常时重新连接到数据库服务器?我目前使用 MSSQL 作为我的数据库。我希望你能在这方面帮助我。谢谢。
解决方案
如果没有后备数据库,您的应用程序将无法有效启动或运行,因此即使您稍后可以重新连接,您也会错过很多启动事件,例如 GORM 更新。
由于您的应用程序在数据库启动之前无法运行,您是否可以延迟启动 Grails 应用程序,直到数据库启动之后?有多种方法可以做到这一点,看起来这样做会给你一个更好、更清晰的初始化过程。
推荐阅读
- mysql - 使用的 SELECT 语句在 codeigniter 中有不同数量的列
- css - Mediawiki:我需要提示如何调试»遇到的异常,类型为“ParseError”«
- c++ - 如何防止 googletest 从我的测试代码中吞下 stdout (std::cout)?
- python - 将一个df的一列连接到另一个df的所有列
- powershell - 仅在文本文件中从第 5 列中删除空格
- git - 如何从本地 git 服务器克隆特定的 Git 分支
- watchkit - iwatch 并发症未在表盘并发症列表中列出,但出现在 iphone 的并发症部分
- javascript - 如何使情况真实 JAVASCRIPT
- c++ - 使用 Xlib 获取应用程序的图标?
- ios - 我可以阻止删除 ios mdm 配置文件吗?