SpringBoot 1.5時的數(shù)據(jù)源配置
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false
升級到SpringBoot 2后逢净,啟動出現(xiàn)問題
The server time zone value '?D1ú±ê×?ê±??' is unrecognized or represents more than one time zone
原因
SpringBoot2.0中使用的jdbc驅(qū)動是mysql-connector-java 8觅赊,需要指定url的時區(qū)serverTimezone软免。
設(shè)置為
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
設(shè)定serverTimezone=UTC衅疙,會比中國時間早8個小時腾夯,如果在中國揭璃,可以選擇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
再次啟動推汽,可以運行补疑,但是會有提示
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.
這時,只要將驅(qū)動由com.mysql.jdbc.Driver改為com.mysql.cj.jdbc.Driver即可歹撒。
spring:
datasource:
## 修改這里
driver-class-name: com.mysql.cj.jdbc.Driver