org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 1 字节的 UTF-8 序列的字节 1 无效。
你是不是在自己的mapper.xml
文件中添加了中文注释(如下):
namespace : 绑定一个Dao/Mapper接口 id: 要实现的接口方法 resultType:返回的参数类型
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- namespace : 绑定一个Dao/Mapper接口 id: 要实现的接口方法 resultType:返回的参数类型-->
<mapper namespace="com.wei.dao.UserDao">
<select id="getUserList" resultType="com.wei.pojo.User">
select * from mybatis.user
</select>
</mapper>
当然,你可以先把自己xml配置中的中文注释先删了,再测试运行一下就知道了
如果运行成功,而且自己想要这些中文注释,那么就按照下面步骤设置一下吧!
**前提:**注意自己的配置文件名字是否写错,比如mapper接口,实体类接口等等…
1、修改自己的idea字符设置(utf-8):
记得点击apply后确定ok;
2、如果害怕以后还会有错,也可以自己手动将xml配置加上去:
1.点击+号,2.选择xml文件 ,3.点击Ok
如果还不能解决,记得将自己的idea重启一下,有时候会有配置缓存
当然最好测试通过是关键。
自己被这个无聊的异常折磨了很久,写下这些希望对大家有用吧,节约一点时间。