运行项目报错
Error querying database. Cause: java.sql.SQLException: No suitable driver found for http://www.example.com
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.sql.SQLException: No suitable driver found for http://www.example.com
### The error may exist in com/pro/dao/UserMapper.xml
### The error may involve com.pro.dao.UserMapper.getUserList
### The error occurred while executing a query
### Cause: java.sql.SQLException: No suitable driver found for http://www.example.com
我的 properties 配置文件是这样的
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/mybatis?useSSL=true&useUnicode=true&characterEncoding=UTF-8
username=root
password=123456
<configuration>
<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>
</configuration>
我查看了一下编译后的文件,发现我的 mybatis-config.xml
文件中的 ${url}
被编译成了 http://www.example.com
url
这个变量被别的配置覆盖了,直接把 url
改成 jdbcUrl
,运行项目问题解决
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<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="${jdbcUrl}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
</configuration>