1. 程式人生 > 其它 >整合SpringBoot與MyBatis時報錯時區異常

整合SpringBoot與MyBatis時報錯時區異常

技術標籤:DeBugjavamybatismysqlspringspring boot

場景:

Spring Boot配置MySQL資料來源時報錯:java.sql.SQLException: 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.

原因:配置項錯誤

原配置

spring:
datasource:
username:root
password:983934
url:jdbc:mysql://127.0.0.1:3306/spring-boot-learn
driver-class-name:com.mysql.cj.jdbc.Driver
type:com.mysql.cj.jdbc.MysqlConnectionPoolDataSource

正確的配置

spring:
datasource:
username:root
password:983934
url:jdbc:mysql://127.0.0.1:3306/spring-boot-learn?serverTimezone=UTC
driver-class-name:com.mysql.cj.jdbc.Driver
type:com.mysql.cj.jdbc.MysqlConnectionPoolDataSource