先检查 jdbc.properties的书写有无空格或者写错 或者 xml文件的书写
1.检查数据库权限设置
create user root@'%' identified by '12345678';
grant all privileges on *.* to root@'%' with grant option;
2.jdbc.properties配置检查(同样适用于mybatis 使用jdbc.properties文件设置不起作用)
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8
characterEncoding=utf-8
jdbc.user=root
jdbc.password=123456
3.报错:java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
增加&allowPublicKeyRetrieval=true
变成jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8&allowPublicKeyRetrieval=true
characterEncoding=utf-8
jdbc.user=root
jdbc.password=123456
4.mybatis.xml代码
<properties resource="jdbc.properties"/>
<dataSource type="POOLED"> <!-- 数据库连接池 -->
<property name="driver" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/> <!-- 127.0.0.1:3306 可省略 -->
<property name="username" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}"/>
</dataSource>