我正在运行在专用服务器中包含REST API的spring boot maven项目的jar,我试图从托管服务器的数据库中获取数据。 托管服务器中的mysql版本:4.1.35
最初几分钟一切都很好,但是在那之后,我得到了这样的错误。
邮递员中的错误: { “ timestamp”:“ 2019-05-14T16:42:03.732 + 0000”, “状态”:500, “错误”:“内部服务器错误”, “,消息”:“通信链接失败\ n \ n成功从服务器接收到的最后一个数据包是473,282毫秒之前。成功发送到服务器的最后一个数据包是9毫秒之前。”, “路径”:“ / api / master / NotificationList” }
服务器错误:
请求处理失败;嵌套的异常是com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败
成功从服务器接收到的最后一个数据包是473,282毫秒之前。成功发送到服务器的最后一个数据包是9毫秒前。根本原因
我正在使用commons-dbcp和mysql-connector-jar
private static String url = "jdbc:mysql://XXX.XXX.XXX.X:3306/dbname?useSSL=false&allowMultiQueries=true&autoReconnect=true";
private static String driverName = "com.mysql.jdbc.Driver";
private static String username = "username";
private static String password = "password";
GenericObjectPool connectionPool = new GenericObjectPool(null);
public DataSource setUp() throws Exception
{
Class.forName(ConnectionManager.driverName).newInstance();
connectionPool.setMinEvictableIdleTimeMillis(1000 * 60 * 30);
connectionPool.setTimeBetweenEvictionRunsMillis(1000 * 60 * 30);
connectionPool.setNumTestsPerEvictionRun(3);
connectionPool.setTestOnBorrow(true);
connectionPool.setTestWhileIdle(true);
connectionPool.setTestOnReturn(false);
connectionPool.setMaxActive(-1);
ConnectionFactory cf = new DriverManagerConnectionFactory( ConnectionManager.url, ConnectionManager.username, ConnectionManager.password);
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(cf, connectionPool, null, "SELECT 1", false, true);
return new PoolingDataSource(connectionPool);
}
public GenericObjectPool getConnectionPool()
{
return connectionPool;
}
pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>