
spring常用dataSource配置如下:
spring:
datasource:
username: root
password: root
url: jdbc:mysql://localhost:3306/datamiddle?characterEncoding=utf8&useSSL=true&rewriteBatchedStatements=true
driver-class-name: com.mysql.jdbc.Driver # 或 `com.mysql.cj.jdbc.Driver而driver-class-name的com.mysql.jdbc.Driver与com.mysql.cj.jdbc.Driver有什么区别呢?
com.mysql.jdbc.Driver是mysql-connector-java 5版本的驱动名称,5版本之后替换为com.mysql.cj.jdbc.Driver
当5之后的版本选择com.mysql.jdbc.Driver的时候,会有警告提示,替换为com.mysql.cj.jdbc.Drive

查看源码可知,老版本的Driver 继承了新版本的Driver,通过继承的方式兼容老版本,并添加了告警提示,如下:

public class Driver extends com.mysql.cj.jdbc.Driver {
public Driver() throws SQLException {
}
static {
System.err.println("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.");
}
}