学习Mybatis时报错:org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession.

2021/10/19 19:09:36

本文主要是介绍学习Mybatis时报错:org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession.,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

学习Mybatis时报错:org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession.

报错详情为;
Caused by: org.apache.ibatis.exceptions.PersistenceException:
Error building SqlSession.
Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 12; 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 com.youhs.utils.MybatisUtils.(MybatisUtils.java:23)

原因

xml文件的注释里写了中文,因此使用utf-8解码会报错。
解决方法:将xml文件的编码方式改为GBK或者UTF-8

<?xml version="1.0" encoding="UTF-8" ?>

改为:

<?xml version="1.0" encoding="GBK" ?>

可参考文章:https://blog.csdn.net/shengsummer/article/details/8934847



这篇关于学习Mybatis时报错:org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession.的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程