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
    
  • 相关阅读:
    linq语法2 GLenn
    sql 拼接字符串 GLenn
    每日算法 20130225 GLenn
    linq语法1 GLenn
    每日算法 20130227 GLenn
    每日算法 20130226 GLenn
    jquery ajax 分页 GLenn
    PhoneGap应用开发对策:如何通过苹果审核?
    Xcode 4.1/4.2/4.3/4.4/4.5 + iOS 5.1.1免证书(iDP)开发+真机调试+生成IPA全攻略
    rails 散乱记录
  • 原文地址:https://www.cnblogs.com/tianwenxin/p/14990682.html
Copyright © 2011-2022 走看看