在 Bluemix 中启动应用程序时无法创建 PoolableConnectionFactory 错误

Cannot create PoolableConnectionFactory error while starting application in Bluemix

将我的 Java 应用程序部署到 IBM Bluemix 后,它无法创建初始数据库连接,因为出现以下错误:

Building new Hibernate SessionFactory 2015-04-11 14:24:04 [main] ERROR o.h.util.JDBCExceptionReporter - Cannot create PoolableConnectionFactory (Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)

我尝试将 "hibernate.current_session_context_class" 设置为 "thread"(当我将相同的应用程序部署到 Google 应用程序引擎时,这解决了问题)但这对 Websphere Liberty 没有帮助简介:

<prop key="hibernate.current_session_context_class" >
        thread
 </prop>

有什么想法吗?

更新 1 --- 这是真正的根本原因。 Bluemix 提供了 ClearDB MySQL 服务,但它的管道无法连接到它:(

Building new Hibernate SessionFactory 2015-04-11 15:04:49 [main] ERROR o.h.util.JDBCExceptionReporter - Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

更新 2 --- 即使是实验性 MySQL DB 也不受限制,如果有任何尝试从管道机器连接:

o.h.util.JDBCExceptionReporter - Cannot create PoolableConnectionFactory (Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.) org.hibernate.exception.GenericJDBCException: Cannot open connection at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140) at org.hibe at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.) at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446) ... 40 more Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

如果您有任何想法,请告诉我。

好的。发生这种情况是因为 Liberty buildpack 在部署到 Bluemix 期间为您自动装配 JDBC 个连接。对于单元测试,您需要向您的应用提供此连接信息。