You must configure either the server or JDBC driver (via the serverTimezone configuration property)

在SpringBoot項目中,在application.properties文件中配置Mysql數據源時出現以下問題:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: GlobalConfigUtils setMetaData Fail !  Cause: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.

原因是數據庫和系統時區差異引起的

解決:

1.降低數據庫版本(不推薦使用)
2.在url後面添加serverTimezone=UTC&characterEncoding=utf-8或
serverTimezone=GMT&characterEncoding=utf-8,如果指定使用gmt+8時區,需要寫成GMT%2B8

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章