SpringBoot 1.5时的数据源配置
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false
升级到SpringBoot 2后,启动出现问题
The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone
原因
SpringBoot2.0中使用的jdbc驱动是mysql-connector-java 8,需要指定url的时区serverTimezone。
设置为
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
设定serverTimezone=UTC,会比中国时间早8个小时,如果在中国,可以选择Asia/Shanghai或者Asia/Hongkong, 或者GMT+8
## 设置为地区名称
jdbc:mysql://localhost:3306/test&useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
## 设置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.
这时,只要将驱动由com.mysql.jdbc.Driver改为com.mysql.cj.jdbc.Driver即可。
spring:
datasource:
## 修改这里
driver-class-name: com.mysql.cj.jdbc.Driver
网友评论