springcloudAlibaba项目连接mysql时(mysql版本8.0.31,Springboot2.2.2,spring cloud Hoxton.SR1,spring cloud alibaba 2.1.0.RELEASE),驱动名称报红,配置如下:
原因:引入的jdbc驱动包和使用的mysql版本不一致。
解决,修改pom文件如下:
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<!--<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.11</version>
</dependency>-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.31</version>
<scope>runtime</scope>
</dependency>
配置文件中有一点需注意:
mysql5.x.x的版本配置应为:“com.mysql.jdbc.driver”
mysql6.x.x及在6以上的版本配置应为:“com.mysql.cj.jdbc.driver”