报错信息如下:
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';characterEncoding=UTF-8&serverTimezone=UTC'.
### The error may exist in UserMapper.xml
### The error may involve com.qf.mapper.UserMapper.findUserById
### The error occurred while executing a query
### Cause: java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';characterEncoding=UTF-8&serverTimezone=UTC'.
properties属性标签要放在最前面配置
以下文件是mybatis-config.xml
<properties resource="db.properties"/>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
以下文件是db.properties
driver = com.mysql.cj.jdbc.Driver
url = jdbc:mysql://localhost:3306/java2217?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
username = root
password = 123456
改正错误:
将&替换成&
替换后代码
driver = com.mysql.cj.jdbc.Driver
url = jdbc:mysql://localhost:3306/java2217?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
username = root
password = 123456