如下圖所示異常:
1 com.mysql.cj.exceptions.InvalidConnectionAttributeException: 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. 2 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_102] 3 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_102] 4 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_102] 5 at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_102]
分析過程:
首先:有一條紅色警告。
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.
按照提示將 spring.datasource.driverClassName 修改為 com.mysql.cj.jdbc.Driver
spring.datasource.driverClassName=com.mysql.jdbc.Driver
其次,我的 mysql-connector-java 版本為 8.0.18,在url上需要添加時區信息:
jdbc:mysql://host:port/dbname?characterEncoding=utf8&serverTimezone=UTC
添加后,異常消失。