exlipse环境Maven因
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 3 字节的 UTF-8 序列的字节 3 无效。
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [XXX.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)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:609)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:510)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at XX.XX(XXXX.java:49)
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(UTF8Reader.java:687)
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:435)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1735)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanData(XMLEntityScanner.java:1234)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanComment(XMLScanner.java:778)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanComment(XMLDocumentFragmentScannerImpl.java:1038)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2988)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:429)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
... 14 more
主要原因是:Eclipse,JDK 与Maven配合还不够默契:
临时解决方法:我将 改为 后可以临时解决编译运行不报错。
最终解决办法:
解决方法如下:
1.检查开发软件的编码是否正确(比如UTF-8)
2.xml头文件设置的编码格式,检查 xml 的头文件和右键属性里面的编码是否一致,
3.使用maven修改默认模式,在 pom.xml 加入如下配置:
4.如果还不行,在pom.xml里设置默认编码
我使用
用文本编辑器将文件查看文件本身就是UTF-8的,只是eclipse自动识别错了,原因是改文件包所在工程确实配置了
我尝试了将出现问题的XML文件和它引用的XML文件都转码为BGK,并设置也编译运行不报错,所以再次证明是eclipse认为是xml文件中声明的编码与xml文件本身保存时的编码不一致,所以编译报错。但这个问题居然eclipse的Validation功能默认不报错,除非你确实把编码设置错误,比如编码本身就是UTF-8,但你声明,这时eclipse的Validation功能就检测出并显示报错了。
所以,综上所述,说明Eclipse确实有些不完善的地方,或者说与Maven配合还不够默契,Maven启用了
我认为Maven私自设置使用系统属性或项目属性代替文件属性值,缺没有告诉Eclipse和JDK,他们没有能配合好,导致问题在编译前和Validation总也没能提前爆出,但是一切都没有完美的东西,所有的问题还是得靠我人自己去解决,提高自己的处理问题的能力,提高技术水平,不停学习领域知识,吸收增长经验是永恒的解决问题之道。
参考:
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException_任何问题都能在StackOverflow找到答案!-CSDN博客_com.sun.org.apache.xerces.internal.impl.io.malform
https://blog.csdn.net/echo_oy/article/details/55118238
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException3字节的UTF-8序列的字节3无效_小异常的博客-CSDN博客_com.sun.org.apache.xerces.internal.impl.io.malform
https://blog.csdn.net/sun8112133/article/details/104693811
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:3字节的UTF-8序列的字节3无效。_肉团子的博客-CSDN博客
https://blog.csdn.net/litterpp/article/details/77678550
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:Invalidbyte2of2-byte_业精于勤荒于嬉-CSDN博客
https://blog.csdn.net/baidu_18607183/article/details/47130707
因配置资源文件而引起的“3字节的UTF-8序列的字节3无效”问题_mr_green1024的博客-CSDN博客_3字节的utf-8序列的字节3无效
https://blog.csdn.net/mr_green1024/article/details/81568675
xml3字节的UTF-8序列的字节3无效_weixin_30493321的博客-CSDN博客_androidmanifest.xml:3字节的utf-8序列的字节3无效。
https://blog.csdn.net/weixin_30493321/article/details/99369306