成功解决:Invalid encoding name “UTF8“

简介: 这篇文章解释了如何解决MyBatis配置文件中由于编码格式错误导致的"Invalid encoding name 'UTF8'"问题,即将`encoding="UTF8"`更正为`encoding="UTF-8"`。

文章底部有个人公众号:热爱技术的小郑。主要分享开发知识、有兴趣的可以关注一下。为何分享? 踩过的坑没必要让别人在再踩,自己复盘也能加深记忆。利己利人、所谓双赢。

前言

出现这个问题可能由于不同的原因、本文是由于**Mapper.xml文件中设置的编码格式问题,需要将encoding="UTF8" 改成encoding="UTF-8"

1、报错信息

Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 38; Invalid encoding name "UTF8".
    at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:263) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:127) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:81) ~[mybatis-3.5.6.jar:3.5.6]
    at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:610) ~[mybatis-spring-2.0.6.jar:2.0.6]
    ... 79 common frames omitted
Caused by: org.xml.sax.SAXParseException: Invalid encoding name "UTF8".
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.xerces.impl.XMLEntityManager.createReader(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.xerces.impl.XMLEntityManager$ScannedEntity.setReader(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.xerces.impl.XMLEntityScanner.setEncoding(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanXMLDeclOrTextDecl(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.xerces.impl.XMLDocumentScannerImpl$XMLDeclDispatcher.dispatch(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) ~[xercesImpl-2.11.0.jar:na]
    at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:261) ~[mybatis-3.5.6.jar:3.5.6]
    ... 82 common frames omitted

2、解决方法

需要将encoding="UTF8" 改成encoding="UTF-8"

在这里插入图片描述

3、成功解决

在此运行程序可以成功启动

在这里插入图片描述

相关文章
|
7月前
|
存储 自然语言处理 Java
UTF-8编码详解
UTF-8编码详解
|
8月前
|
存储 自然语言处理 关系型数据库
utf-8和utf-8 mb4区别
总之,`utf-8`和 `utf8mb4`都是用于表示Unicode字符集中的字符,区别在于 `utf8mb4`支持更广泛的字符范围,适用于需要存储特殊字符(如Emoji)的情况。 买CN2云服务器,免备案服务器,高防服务器,就选蓝易云。百度搜索:蓝易云
203 5
|
Java 测试技术
body-parser:unsupported content encoding 错误
最近遇到了一个奇怪的问题,关于body-parser报错,我本地调用没问题,使用测试工具没问题,这种方案都没问题,就和我对接的程序调用有问题,于是开始了面向百度编程,查到了两种解决方案:
561 0
body-parser:unsupported content encoding 错误
|
关系型数据库 MySQL Shell
[ERROR] COLLATION ‘utf8_unicode_ci‘ is not valid for CHARACTER SET ‘latin1‘
[ERROR] COLLATION ‘utf8_unicode_ci‘ is not valid for CHARACTER SET ‘latin1‘
|
JSON PHP 数据格式
php json_encode JSON_ERROR_UTF8 Malformed UTF-8 characters, possibly incorrectly encoded
php json_encode JSON_ERROR_UTF8 Malformed UTF-8 characters, possibly incorrectly encoded
399 0
|
网络安全 Windows
svn locale Can&#39;t convert string from native encoding to &#39;UTF-8&#39;
svn 提交代码报错,原因很简单,编码的问题 报错信息 shell&gt;svn update test svn: warning: cannot set LC_CTYPE locale svn: warning: environment variable LC_CTYPE is UTF-8 svn: warning: please check that
1817 0