最近做毕设,使用springBoot + electron-vue + vue全家桶,构建项目。
后台编写完成后,为了方便,就把后台部署在云服务器上面,方便联调。然而,部署完成后,连接到后台,调用后台数据接口,浏览器控制台报错如下:请求超时,

再看
NetWork
,请求的接口变成红色,发现Provisional headers are shown
,查看Response
,服务器并没有响应,看来,因为浏览器 Provisional headers are shown 无法向后台发送请求。

于是,只能排查问题了,首先,查看
apache-tomcat日志
,在你安装的apache-tomcat目录下,logs/catalina.out
,发现了如下警告:
Sun May 06 22:01:41 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
07-May-2018 11:12:32.122 WARNING [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [dorm] registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
07-May-2018 11:12:32.124 WARNING [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [dorm] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
07-May-2018 11:12:32.125 WARNING [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [dorm] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:64)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
查看springBoot项目中的配置文件:
spring:
datasource:
name: test
# 数据库连接
url: jdbc:mysql://localhost:3306/xcfw_dorm?&characterEncoding=utf8&useSSL=true&allowMultiQueries=true
username: root
...
在连接数据库中,使用了ssl,useSSL=true
,然而我们在服务器端并没有做ssl的验证,所以导致连接不上。问题找到了,解决如下:
修改mysql配置文件/etc/my.cnf
[root@localhost]# vim /etc/my.cnf
# 在文件后面加入如下配置
# disable_ssl
skip_ssl
重启mysql
[root@localhost]# service mysqld restart
查看mysql表中记录,已禁用ssl
[root@localhost]# mysql -u root -p
mysql> show global variables like '%ssl%';
+---------------+----------+
| Variable_name | Value |
+---------------+----------+
| have_openssl | DISABLED |
| have_ssl | DISABLED |
| ssl_ca | |
| ssl_capath | |
| ssl_cert | |
| ssl_cipher | |
| ssl_crl | |
| ssl_crlpath | |
| ssl_key | |
+---------------+----------+
9 rows in set (0.00 sec)
再次访问,就能正常访问了

当然,我们也可以在springboot配置数据库连接语句中,不使用ssl,即将:
spring:
datasource:
name: test
# 数据库连接
url: jdbc:mysql://localhost:3306/xcfw_dorm?&characterEncoding=utf8&useSSL=true&allowMultiQueries=true
username: root
...
中的useSSL=true
改为: useSSL=false
.同样能解决问题。
ps:
在mysql5.7最新版,已经默认启用了ssl。在配置服务器环境(2018-05-7配置)的时候,安装了mysql5.7就默认启用了ssl。查看之前在办公室配置的服务器mysql5.7,并没有默认启用ssl,因此没有发现此问题。
到此,踩坑结束。
网友评论