2019.3.31
1.MESSAGE: closing inbound before receiving peer’s close_notify
问题背景是,我已经在linux端建立好了数据库,navicat也可以正常访问,但是在idea端测试的时候就出不来。
配置文件(.yml)如下:
spring:
datasource:
username: root
password: 123456
url: jdbc:mysql://192.168.254.129:3306/
driver-class-name: com.mysql.cj.jdbc.Driver
测试文件如下:
package com.learning.learning11;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLDataException;
import java.sql.SQLException;
@RunWith(SpringRunner.class)
@SpringBootTest
public class Learning11ApplicationTests {
@Autowired
DataSource dataSource;
@Test
public void contextLoads() throws SQLException {
System.out.println(dataSource.getClass());
Connection connection = dataSource.getConnection();
System.out.println(connection);
connection.close();
}
}
出错的原因:
找到一些帖子说在配置连接数据库url时,要加上useSSL=false
。
然后将配置文件修改如下:
spring:
datasource:
username: root
password: 123456
url: jdbc:mysql://192.168.254.129:3306/?serverTimezone=GMT%2B8&useSSL=false
driver-class-name: com.mysql.cj.jdbc.Driver
serverTimezone=GMT%2B8
表示将服务器的时间转换成北京时间东八区,这个没有什么关系,加不加都可以。主要是useSSL=false
要加上。
我看了一下,SSL的功能是让MySQL的数据通道加密,可能高版本的MySQL默认是设置有SSL的,但是这里SSL的关闭之类的没有处理好。所以这里取消使用SSL就可以了。
参考:https://blog.youkuaiyun.com/qq_34075488/article/details/85106860