spring连接mysql5.7_springBoot + mysql5.7踩坑记 Provisional headers are shown

最近做毕设,使用springBoot + electron-vue + vue全家桶,构建项目。

后台编写完成后,为了方便,就把后台部署在云服务器上面,方便联调。然而,部署完成后,连接到后台,调用后台数据接口,浏览器控制台报错如下:请求超时,

b77827e69e02?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

浏览器控制台报错

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

b77827e69e02?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

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)

再次访问,就能正常访问了

b77827e69e02?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

正常访问

当然,我们也可以在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,因此没有发现此问题。

到此,踩坑结束。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值