zoukankan      html  css  js  c++  java
  • SpringBoot整合mysql-8 遇见的bug

    问题描述

    Maven中引入SpringBoot 2.1.6.RELEASE版本,导致项目运行失败,错误信息如下:

    com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the
    server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_131]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_131]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_131]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_131]
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.16.jar:8.0.16]

    bug出现原因

    SpringBoot 2.1.6.RELEASE版本,默认使用的是 mysql-8.0.16 版本,这个版本导入的驱动和低版本不一样,需要修改一下。

    解决方案

    方案一:使用低版本mysql

    Pom.xml

    • 使用较低版本
    <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.1.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    

    application.yml

    spring:
      datasource:
        username: root
        password: root
        url: jdbc:mysql://127.0.0.1:3306/mybatis-example?useUnicode=true&characterEncoding=utf8
        driver-class-name: com.mysql.jdbc.Driver
    

    方案二:修改yml文件

    Pom.xml

    • 使用较高版本
     <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.6.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    

    application.yml

    • url 中添加时区属性
    • driver 的驱动名称发生变化
    spring:
      datasource:
        username: root
        password: root
        url: jdbc:mysql://127.0.0.1:3306/mybatis-example?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
        driver-class-name: com.mysql.cj.jdbc.Driver
    
  • 相关阅读:
    dbcc练习1
    查看底层硬件信息
    mkfs.xfs命令没找到
    Linux清空内存缓存
    常用CentOS 6/7 扩展源
    CentOS 6.x安装gcc 4.8/4.9/5.2
    根据SSH私钥(private key)计算SSH公钥(public key)
    Mac下Sublime Text Vim模式 方向键无法长按
    【转载】Hadoop和大数据:60款顶级大数据开源工具
    Linux Shell产生16进制随机数
  • 原文地址:https://www.cnblogs.com/tianwenxin/p/14990682.html
Copyright © 2011-2022 走看看