mybatis将mybatis-config.xml配置文件抽取到db.properties出现错误

报错信息如下:

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&amp;characterEncoding=UTF-8&amp;serverTimezone=UTC
username = root
password = 123456

改正错误:

将&amp;替换成&

替换后代码

driver = com.mysql.cj.jdbc.Driver
url = jdbc:mysql://localhost:3306/java2217?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
username = root
password = 123456

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值