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