Error building SqlSession. ### The error may exist in dao/UserMapper.xml ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration(2 字节的 UTF-8 序列的字节 2 无效。)

2023-06-08,,

关于在学习Mybatis框架时运行报错

Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in dao/UserMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列的字节 2 无效
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
at utils.MybatisUtils.<clinit>(MybatisUtils.java:21)
... 1 more

个人在网上搜索了许多相关的资料都无济于事,于是检查报错内容Error parsing SQL Mapper Configuration代表xml的配置出现了问题,而且后面又有错误2 字节的 UTF-8 序列的字节 2 无效。,猜测是xml中的文字编码除了问题

解决问题

将xml文件中的汉字全部删除即可;

经测试发现,将UserMapper.xml下的文字删除即可;

参考

SAX错误– MalformedByteSequenceException:1字节UTF-8序列的无效字节1。

Error building SqlSession. ### The error may exist in dao/UserMapper.xml ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration(2 字节的 UTF-8 序列的字节 2 无效。)的相关教程结束。

《Error building SqlSession. ### The error may exist in dao/UserMapper.xml ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration(2 字节的 UTF-8 序列的字节 2 无效。).doc》

下载本文的Word格式文档,以方便收藏与打印。