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]
SpringBoot 2.1.6.RELEASE版本,默认使用的是 mysql-8.0.16 版本,这个版本导入的驱动和低版本不一样,需要修改一下。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
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
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
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
原文:https://www.cnblogs.com/tianwenxin/p/14990682.html