成功解决: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、成功解决

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

在这里插入图片描述

相关文章
|
4月前
|
JSON 数据格式
Content type ‘text/plain;charset=UTF-8‘ not supported,这里要把测试文件转为json格式
Content type ‘text/plain;charset=UTF-8‘ not supported,这里要把测试文件转为json格式
|
6月前
|
存储 自然语言处理 关系型数据库
utf-8和utf-8 mb4区别
总之,`utf-8`和 `utf8mb4`都是用于表示Unicode字符集中的字符,区别在于 `utf8mb4`支持更广泛的字符范围,适用于需要存储特殊字符(如Emoji)的情况。 买CN2云服务器,免备案服务器,高防服务器,就选蓝易云。百度搜索:蓝易云
169 5
|
6月前
|
XML 数据格式
restTemplat发post请求报错Content type ‘application/xml;charset=UTF-8‘ not supported“
restTemplat发post请求报错Content type ‘application/xml;charset=UTF-8‘ not supported“
244 1
|
Java 测试技术
body-parser:unsupported content encoding 错误
最近遇到了一个奇怪的问题,关于body-parser报错,我本地调用没问题,使用测试工具没问题,这种方案都没问题,就和我对接的程序调用有问题,于是开始了面向百度编程,查到了两种解决方案:
536 0
body-parser:unsupported content encoding 错误
|
JSON Java 数据格式
HttpMediaTypeNotSupportedException: Content type ‘application.yml/json;charset=UTF-8‘ not supported
HttpMediaTypeNotSupportedException: Content type ‘application.yml/json;charset=UTF-8‘ not supported
326 0
|
SQL 存储 关系型数据库
CHARACTER SET utf8 COLLATE utf8_general_ci
CHARACTER SET utf8 COLLATE utf8_general_ci
|
关系型数据库 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
371 0
成功解决 SyntaxError: Non-UTF-8 code starting with \xc0 in file but no encoding declared; see http://p
成功解决 SyntaxError: Non-UTF-8 code starting with \xc0 in file but no encoding declared; see http://p
成功解决 SyntaxError: Non-UTF-8 code starting with \xc0 in file but no encoding declared; see http://p
|
Python
Sublime Text: [Decode error - output not utf-8]
今天编译Python时, 输出窗口信息出现: [Decode error - output not utf-8][Decode error - output not utf-8]   发现是print不支持中文字符的输出, 需要修改python的build的setting, 打开Python.
2355 0