MySQL服务端和客户端不一致
服务可以正常启动,但数据库操作就一直等待中。异常日志返回如下:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 3 milliseconds ago. The last packet sent successfully to the server was 3 milliseconds ago.
Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
这里的原因是mysql版本问题导致的,我本地MySQL服务端的版本是:
mysql Ver 8.0.22 for osx10.16 on x86_64 (Homebrew)
但maven配置MySQL用的却是5.7的客户端,就会导致链接MySQL数据库异常,一直处于等待中。
解决方法
更改maven中MySQL依赖包的版本,然后重新编译就可以了。
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
MySQL连接配置问题
服务根本启动不起来,异常日志如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cloud.autoconfigure.RefreshAutoConfiguration$JpaInvokerConfiguration': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [cn/lalaframework/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.RuntimeException: dynamic-datasource Please check the setting of primary
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [cn/lalaframework/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.RuntimeException: dynamic-datasource Please check the setting of primary
意思大致是数据库连接的主配置获取不到,指定master主配置就可以了。
错误配置:
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/cp_mcv_monitor?characterEncoding=utf8&useSSL=true
spring.datasource.username=root
spring.datasource.password=root
正确配置:
spring.datasource.dynamic.primary=master
spring.datasource.dynamic.datasource.master.url=jdbc:mysql://localhost:3306/cp_mcv_monitor?characterEncoding=utf8&useSSL=true
spring.datasource.dynamic.datasource.master.username=root
spring.datasource.dynamic.datasource.master.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。