將項(xiàng)目由SpringBoot 1.5升級(jí)到2.0時(shí)要修改數(shù)據(jù)源配置

SpringBoot 1.5時(shí)的數(shù)據(jù)源配置

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false

升級(jí)到SpringBoot 2后,啟動(dòng)出現(xiàn)問題

The server time zone value '?D1ú±ê×?ê±??' is unrecognized or represents more than one time zone

原因

SpringBoot2.0中使用的jdbc驅(qū)動(dòng)是mysql-connector-java 8,需要指定url的時(shí)區(qū)serverTimezone。
設(shè)置為

jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC

設(shè)定serverTimezone=UTC,會(huì)比中國(guó)時(shí)間早8個(gè)小時(shí),如果在中國(guó),可以選擇Asia/Shanghai或者Asia/Hongkong, 或者GMT+8

## 設(shè)置為地區(qū)名稱
jdbc:mysql://localhost:3306/test&useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai

## 設(shè)置GMT+8
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8

再次啟動(dòng),可以運(yùn)行,但是會(huì)有提示

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

這時(shí),只要將驅(qū)動(dòng)由com.mysql.jdbc.Driver改為com.mysql.cj.jdbc.Driver即可。

spring:
  datasource:
    ## 修改這里
    driver-class-name: com.mysql.cj.jdbc.Driver
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容