by:com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:3字节的UTF-8序列的字节3无效

原创 Laughing  2019-07-11 11:37  阅读 11 次 评论 0 条

关键错误信息如下所示

  1. Context initialization failedorg.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring-config.xml]; nested exception is com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 3 字节的 UTF-8 序列的字节 3 无效。  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:410) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125) ~[spring-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94) ~[spring-web-4.2.2.RELEASE.jar:4.2.2.RELEASE] at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129) ~[spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]   at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:605) ~[spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:509) ~[spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446) ~[spring-web-4.2.2.RELEASE.jar:4.2.2.RELEASE] at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328) ~[spring-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) [spring-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4738) [catalina.jar:8.0.28]  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5181) [catalina.jar:8.0.28]  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.0.28]   at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) [catalina.jar:8.0.28]    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) [catalina.jar:8.0.28]    at java.util.concurrent.FutureTask.run(Unknown Source) [na:1.8.0_60]    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_60]  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_60] at java.lang.Thread.run(Unknown Source) [na:1.8.0_60]Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 3 字节的 UTF-8 序列的字节 3 无效。  at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown Source) ~[na:1.8.0_60] at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown Source) ~[na:1.8.0_60]    at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown Source) ~[na:1.8.0_60] at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanData(Unknown Source) ~[na:1.8.0_60] at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanComment(Unknown Source) ~[na:1.8.0_60]    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanComment(Unknown Source) ~[na:1.8.0_60]    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source) ~[na:1.8.0_60] at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source) ~[na:1.8.0_60]   at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source) ~[na:1.8.0_60] at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) ~[na:1.8.0_60]   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) ~[na:1.8.0_60]   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) ~[na:1.8.0_60]   at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) ~[na:1.8.0_60]    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source) ~[na:1.8.0_60]    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source) ~[na:1.8.0_60] at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:429) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]   at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]    ... 22 common frames omitted  

解决方法:

经检查是xml文件问题,有以下两种原因:
1.编码格式,2.文件中有中文(更多可能是中文的空格) 【自己认真检查即可】
原xml文件首行:
修改为GBK就可以了,即下所示

历史上的今天:

本文地址:https://www.lisen.me/by-com-sun-org-apache-xerces-internal-impl-io-malformedbytesequenceexception-byte-3-of-the-3-byte-utf-8-sequence-is-invalid.html
版权声明:本文为原创文章,版权归 木子网 所有,欢迎分享本文,转载请保留出处!

发表评论


表情