Java Spring启动应用程序(使用mybatis)在引入CA签名证书后停止连接mysql
大约一周前,开发环境(AWS EC2实例)中的一个spring引导应用程序突然停止了连接,该应用程序在此之前使用SSL成功连接到MySql。以下是从无用堆栈跟踪中选择的内容:Java Spring启动应用程序(使用mybatis)在引入CA签名证书后停止连接mysql,java,mysql,spring-boot,ssl,mybatis,Java,Mysql,Spring Boot,Ssl,Mybatis,大约一周前,开发环境(AWS EC2实例)中的一个spring引导应用程序突然停止了连接,该应用程序在此之前使用SSL成功连接到MySql。以下是从无用堆栈跟踪中选择的内容: ### Error querying database. Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet sent successfully to the s
### Error querying database. Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: 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.
### The error may exist in com/domain/app/data/mybatis/mappers/SomeMapper.xml
### The error may involve com.domain.app.data.mybatis.mappers.SomeMapper.getUserByUsername
### The error occurred while executing a query
### Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: 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.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:87)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:93)
at com.sun.proxy.$Proxy91.getUserByUsername(Unknown Source)
at com.domain.app.security.SomeService.loadUserByUsername(SomeService.java:32)
at org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:108)
... 96 more
Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
...
Caused by: java.net.ConnectException: Connection timed out (Connection timed out)
一些事实:
- 当从我的本地计算机运行时,完全相同的应用程序构建工作(具有相同的db连接信息)。可能排除了配置错误的应用程序代码
- mysql驻留在一个单独的EC2实例上,我可以通过“故障”EC2实例上的CLI连接到mysql。可能排除了安全/ACL问题
- 连接字符串的形式如下:jdbc:mysql://x.x.x.x:3306/db_name?useSSL=true&verifyServerCertificate=true&requireSSL=true&autoReconnect=true,{db username},{db password}。同样,这个字符串在我自己的机器上使用时可以工作
- 大约两周前,CA签署的ssl证书被添加到java密钥库中的spring boot应用程序中。相同的证书没有添加到mysql,mysql使用的是自生成和自签名的证书。有一个很小的,几乎不可信的机会,应用程序没有在有故障的环境中测试过,尽管我很确定我从那时起就使用过这个环境