SpringBoot配置mysql8.0以上版本的一些坑

当安装了Mysql8.0以上版本,搭建SpringBoot环境时启动项目时会遇到以下错误:

(1)第一个坑

Caused by javax.net.ssl.SSLHandshakeException:java.security.cert.certificateException

解决办法

pom.xml中的mysql驱动包依赖修改为

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>

application.properties文件中的配置内容:

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

driverClassName: com.mysql.cj.jdbc.Driver

 

 

(2)第二个坑

java.sql.SQLException: The connection property 'zeroDateTimeBehavior' acceptable values are: 'CONVERT_TO_NULL', 'EXCEPTION' or 'ROUND'. The value 'convertToNull' is not acceptable.
java.lang.IllegalArgumentException: No enum constant com.mysql.cj.conf.PropertyDefinitions.ZeroDatetimeBehavior.CONVERTTONULL

解决办法:由于MySql废弃了convertToNull该写法,改为 CONVERT_TO_NULL

                url=jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxx?characterEncoding=utf8&useSSL=true&serverTimezone=UTC&zeroDateTimeBehavior=CONVERT_TO_NULL

  • 9
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在Spring Boot中配置MySQL 8.0的方式有多种。根据引用的内容,可以通过修改`pom.xml`文件和`application.properties`文件来配置MySQL 8.0。 首先,在`pom.xml`文件中添加以下依赖项: ``` <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.30</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> ``` 这样就集成了MySQL数据库和Spring Boot JDBC。 接下来,打开`application.properties`文件,根据需要进行以下修改: ``` spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://127.0.0.1:3306/harvest?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true spring.datasource.username=root spring.datasource.password=root ``` 这样,你就成功地配置了Spring Boot与MySQL 8.0的连接。请注意,`spring.datasource.url`中的参数可以根据你的需求进行修改,比如设置字符编码、关闭SSL等等。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [SpringBoot连接MySQL8.0配置问题](https://blog.csdn.net/Moddlec/article/details/87382824)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Springboot 连接 Mysql](https://blog.csdn.net/qq_41749451/article/details/126141915)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值