成功解决: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月前
|
存储 自然语言处理 关系型数据库
utf-8和utf-8 mb4区别
总之,`utf-8`和 `utf8mb4`都是用于表示Unicode字符集中的字符,区别在于 `utf8mb4`支持更广泛的字符范围,适用于需要存储特殊字符(如Emoji)的情况。 买CN2云服务器,免备案服务器,高防服务器,就选蓝易云。百度搜索:蓝易云
195 5
|
JSON Java 数据格式
HttpMediaTypeNotSupportedException: Content type ‘application.yml/json;charset=UTF-8‘ not supported
HttpMediaTypeNotSupportedException: Content type ‘application.yml/json;charset=UTF-8‘ not supported
345 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‘
|
数据库
Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE)
版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用自由转载-保持署名-注明出处,谢谢。 https://blog.csdn.net/testcs_dn/article/details/82016025 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation 'like' 这个问题一看就是编码的问题。
6355 0
|
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
389 0
成功解决SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 6-7: malformed
成功解决SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 6-7: malformed