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
    
  • 相关阅读:
    celery的使用和原理
    内核通知链
    数据流中的中位数
    二叉搜索树的后序遍历序列
    Javascript设计模式系统讲解与应用,JS设计模式详解
    微服务系列之ZooKeeper注册中心和Nacos注册中心
    微信小程序开发详解:小程序入门与实战-纯正商业级应用技术
    Java零基础该怎么去学习Java?学好Java应该如何去做?
    Flutter从入门到进阶实战携程网App项目详解
    Python升级3.6强力Django+杀手级Xadmin打造在线教育平台
  • 原文地址:https://www.cnblogs.com/tianwenxin/p/14990682.html
Copyright © 2011-2022 走看看