澳门新浦京8455com有限公司欢迎您!

php解决xml提醒 Invalid byte 1 of 1-byte UTF-8 sequence

时间:2020-02-12 23:31

错误提示
Invalid byte 1 of 1-byte UTF-8 sequence
原因分析
在中文版的window下java的默认的编码为GBK,也就是所虽然我们标识了要将xml保存为utf-8格式但实际上文件是以GBK格式来保存的,所以这也就是为什么能够我们使用GBK、GB2312编码来生成xml文件能正确的被解析,而以UTF-8格式生成的文件不能被xml解析器所解析的原因。

Invalid byte 1 of 1-byte UTF-8 sequence

早上在测试代码的时候遇到这个问题:

把xml的encoding属性值UTF-8改为UTF8
org.xml.sax.SAXParseException: Content is not allowed in trailing section
把先要解析和字符串trim()一下即可解决问题。
解决:
1、最简单就是把

把xml的encoding属性值UTF-8改为UTF8

F:Javajdk1.7.0_79binjava -ea -Didea.launcher.port=7533 "-Didea.launcher.bin.path=C:Program Files (x86)JetBrainsIntelliJ IDEA 2016.1.1bin" -Didea.junit.sm_runner -Dfile.encoding=UTF-8 -classpath "C:Program Files (x86)JetBrainsIntelliJ IDEA 2016.1.1libidea_rt.jar;C:Program Files (x86)JetBrainsIntelliJ IDEA 2016.1.1pluginsjunitlibjunit-rt.jar;F:Javajdk1.7.0_79jrelibcharsets.jar;F:Javajdk1.7.0_79jrelibdeploy.jar;F:Javajdk1.7.0_79jrelibextaccess-bridge-64.jar;F:Javajdk1.7.0_79jrelibextdnsns.jar;F:Javajdk1.7.0_79jrelibextjaccess.jar;F:Javajdk1.7.0_79jrelibextlocaledata.jar;F:Javajdk1.7.0_79jrelibextsunec.jar;F:Javajdk1.7.0_79jrelibextsunjce_provider.jar;F:Javajdk1.7.0_79jrelibextsunmscapi.jar;F:Javajdk1.7.0_79jrelibextzipfs.jar;F:Javajdk1.7.0_79jrelibjavaws.jar;F:Javajdk1.7.0_79jrelibjce.jar;F:Javajdk1.7.0_79jrelibjfr.jar;F:Javajdk1.7.0_79jrelibjfxrt.jar;F:Javajdk1.7.0_79jrelibjsse.jar;F:Javajdk1.7.0_79jrelibmanagement-agent.jar;F:Javajdk1.7.0_79jrelibplugin.jar;F:Javajdk1.7.0_79jrelibresources.jar;F:Javajdk1.7.0_79jrelibrt.jar;I:IDEAerptargettest-classes;I:IDEAerptargetclasses;I:mavenrepositoryjunitjunit4.11junit-4.11.jar;I:mavenrepositoryorghamcresthamcrest-core1.3hamcrest-core-1.3.jar;I:mavenrepositoryorgspringframeworkspring-core3.2.2.RELEASEspring-core-3.2.2.RELEASE.jar;I:mavenrepositorycommons-loggingcommons-logging1.1.1commons-logging-1.1.1.jar;I:mavenrepositoryorgspringframeworkspring-beans3.2.2.RELEASEspring-beans-3.2.2.RELEASE.jar;I:mavenrepositoryorgspringframeworkspring-jdbc3.2.2.RELEASEspring-jdbc-3.2.2.RELEASE.jar;I:mavenrepositoryorgspringframeworkspring-tx3.2.2.RELEASEspring-tx-3.2.2.RELEASE.jar;I:mavenrepositoryorgspringframeworkspring-web3.2.2.RELEASEspring-web-3.2.2.RELEASE.jar;I:mavenrepositoryaopallianceaopalliance1.0aopalliance-1.0.jar;I:mavenrepositoryorgspringframeworkspring-aop3.2.2.RELEASEspring-aop-3.2.2.RELEASE.jar;I:mavenrepositoryorgspringframeworkspring-context3.2.2.RELEASEspring-context-3.2.2.RELEASE.jar;I:mavenrepositoryorgspringframeworkspring-expression3.2.2.RELEASEspring-expression-3.2.2.RELEASE.jar;I:mavenrepositoryorgspringframeworkspring-orm3.2.2.RELEASEspring-orm-3.2.2.RELEASE.jar;I:mavenrepositoryorgspringframeworkspring-context-support3.2.2.RELEASEspring-context-support-3.2.2.RELEASE.jar;I:mavenrepositoryorgapachestrutsstruts2-core2.3.14.2struts2-core-2.3.14.2.jar;I:mavenrepositoryorgapachestrutsxworkxwork-core2.3.14.2xwork-core-2.3.14.2.jar;I:mavenrepositoryorgfreemarkerfreemarker2.3.19freemarker-2.3.19.jar;I:mavenrepositoryognlognl3.0.6ognl-3.0.6.jar;I:mavenrepositoryjavassistjavassist3.11.0.GAjavassist-3.11.0.GA.jar;I:mavenrepositorycommons-fileuploadcommons-fileupload1.2.2commons-fileupload-1.2.2.jar;I:mavenrepositorycommons-iocommons-io2.0.1commons-io-2.0.1.jar;I:mavenrepositoryorgapachestrutsstruts2-spring-plugin2.3.14.2struts2-spring-plugin-2.3.14.2.jar;I:mavenrepositoryorgapachecommonscommons-lang33.1commons-lang3-3.1.jar;I:mavenrepositoryasmasm3.3asm-3.3.jar;I:mavenrepositoryasmasm-commons3.3asm-commons-3.3.jar;I:mavenrepositoryasmasm-tree3.3asm-tree-3.3.jar;I:mavenrepositoryorgmybatismybatis3.2.2mybatis-3.2.2.jar;I:mavenrepositoryorgmybatismybatis-spring1.2.0mybatis-spring-1.2.0.jar;I:mavenrepositorymysqlmysql-connector-java5.1.10mysql-connector-java-5.1.10.jar;I:mavenrepositorycomcloudhopperproxoolproxool.9.1proxool-0.9.1.jar;I:mavenrepositorycomcloudhopperproxoolproxool-cglib.9.1proxool-cglib-0.9.1.jar;I:mavenrepositoryavalon-frameworkavalon-framework-api4.3avalon-framework-api-4.3.jar;I:mavenrepositoryavalon-logkitavalon-logkit2.1avalon-logkit-2.1.jar;I:mavenrepositorylog4jlog4j1.2.11log4j-1.2.11.jar;I:mavenrepositoryjavaxservletservlet-api2.3servlet-api-2.3.jar;I:mavenrepositorygeronimo-specgeronimo-spec-javamail1.3.1-rc3geronimo-spec-javamail-1.3.1-rc3.jar;I:mavenrepositorygeronimo-specgeronimo-spec-jms1.1-rc4geronimo-spec-jms-1.1-rc4.jar;I:mavenrepositorycomsdiconsjsontoolsjsontools-core1.7jsontools-core-1.7.jar;I:mavenrepositoryantlrantlr2.7.6antlr-2.7.6.jar;I:mavenrepositoryorgaspectjaspectjweaver1.5.4aspectjweaver-1.5.4.jar;I:mavenrepositorytaglibsstandard1.0.6standard-1.0.6.jar;I:mavenrepositorydwrdwr1.1.3dwr-1.1.3.jar;I:mavenrepositorybsfbsf2.3.0bsf-2.3.0.jar;I:mavenrepositorydom4jdom4j1.6.1dom4j-1.6.1.jar;I:mavenrepositoryxml-apisxml-apis1.0.b2xml-apis-1.0.b2.jar;I:mavenrepositoryjdomjdom1.0jdom-1.0.jar;I:mavenrepositoryxomxom1.1xom-1.1.jar;I:mavenrepositoryxercesxmlParserAPIs2.6.2xmlParserAPIs-2.6.2.jar;I:mavenrepositoryxercesxercesImpl2.6.2xercesImpl-2.6.2.jar;I:mavenrepositoryxalanxalan2.7.0xalan-2.7.0.jar;I:mavenrepositoryjaxenjaxen1.1-beta-8jaxen-1.1-beta-8.jar;I:mavenrepositoryorgspringframeworkspring-test4.1.6.RELEASEspring-test-4.1.6.RELEASE.jar" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 manager.admin.AdminUserDaoTest,testFindAdminUsersByAdminId
[framework] 2016-08-15 09:39:30,002 - org.springframework.core.env.StandardEnvironment -1    [main] DEBUG org.springframework.core.env.StandardEnvironment  - Initializing new StandardEnvironment
[framework] 2016-08-15 09:39:30,005 - org.springframework.core.env.StandardEnvironment -4    [main] DEBUG org.springframework.core.env.StandardEnvironment  - Adding [systemProperties] PropertySource with lowest search precedence
[framework] 2016-08-15 09:39:30,006 - org.springframework.core.env.StandardEnvironment -5    [main] DEBUG org.springframework.core.env.StandardEnvironment  - Adding [systemEnvironment] PropertySource with lowest search precedence
[framework] 2016-08-15 09:39:30,007 - org.springframework.core.env.StandardEnvironment -6    [main] DEBUG org.springframework.core.env.StandardEnvironment  - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
[framework] 2016-08-15 09:39:30,012 - org.springframework.context.support.ClassPathXmlApplicationContext -11   [main] INFO  org.springframework.context.support.ClassPathXmlApplicationContext  - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@d809bd3: startup date [Mon Aug 15 09:39:30 CST 2016]; root of context hierarchy
[framework] 2016-08-15 09:39:30,050 - org.springframework.core.env.StandardEnvironment -49   [main] DEBUG org.springframework.core.env.StandardEnvironment  - Initializing new StandardEnvironment
[framework] 2016-08-15 09:39:30,050 - org.springframework.core.env.StandardEnvironment -49   [main] DEBUG org.springframework.core.env.StandardEnvironment  - Adding [systemProperties] PropertySource with lowest search precedence
[framework] 2016-08-15 09:39:30,050 - org.springframework.core.env.StandardEnvironment -49   [main] DEBUG org.springframework.core.env.StandardEnvironment  - Adding [systemEnvironment] PropertySource with lowest search precedence
[framework] 2016-08-15 09:39:30,051 - org.springframework.core.env.StandardEnvironment -50   [main] DEBUG org.springframework.core.env.StandardEnvironment  - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
[framework] 2016-08-15 09:39:30,051 - org.springframework.core.env.StandardEnvironment -50   [main] DEBUG org.springframework.core.env.StandardEnvironment  - Initializing new StandardEnvironment
[framework] 2016-08-15 09:39:30,051 - org.springframework.core.env.StandardEnvironment -50   [main] DEBUG org.springframework.core.env.StandardEnvironment  - Adding [systemProperties] PropertySource with lowest search precedence
[framework] 2016-08-15 09:39:30,051 - org.springframework.core.env.StandardEnvironment -50   [main] DEBUG org.springframework.core.env.StandardEnvironment  - Adding [systemEnvironment] PropertySource with lowest search precedence
[framework] 2016-08-15 09:39:30,052 - org.springframework.core.env.StandardEnvironment -51   [main] DEBUG org.springframework.core.env.StandardEnvironment  - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
[framework] 2016-08-15 09:39:30,060 - org.springframework.beans.factory.xml.XmlBeanDefinitionReader -59   [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from class path resource [applicationContext-commons.xml]
[framework] 2016-08-15 09:39:30,134 - org.springframework.beans.factory.xml.DefaultDocumentLoader -133  [main] DEBUG org.springframework.beans.factory.xml.DefaultDocumentLoader  - Using JAXP provider [org.apache.xerces.jaxp.DocumentBuilderFactoryImpl]
[framework] 2016-08-15 09:39:30,258 - org.springframework.beans.factory.xml.PluggableSchemaResolver -257  [main] DEBUG org.springframework.beans.factory.xml.PluggableSchemaResolver  - Trying to resolve XML entity with public id [null] and system id [http://www.springframework.org/schema/beans/spring-beans-3.0.xsd]
[framework] 2016-08-15 09:39:30,258 - org.springframework.beans.factory.xml.PluggableSchemaResolver -257  [main] DEBUG org.springframework.beans.factory.xml.PluggableSchemaResolver  - Loading schema mappings from [META-INF/spring.schemas]
[framework] 2016-08-15 09:39:30,271 - org.springframework.beans.factory.xml.PluggableSchemaResolver -270  [main] DEBUG org.springframework.beans.factory.xml.PluggableSchemaResolver  - Loaded schema mappings: {http://mybatis.org/schema/mybatis-spring-1.2.xsd=org/mybatis/spring/config/mybatis-spring-1.2.xsd, http://www.springframework.org/schema/jee/spring-jee-3.2.xsd=org/springframework/ejb/config/spring-jee-3.2.xsd, http://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.2.xsd, http://www.springframework.org/schema/task/spring-task.xsd=org/springframework/scheduling/config/spring-task-3.2.xsd, http://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd, http://www.springframework.org/schema/cache/spring-cache.xsd=org/springframework/cache/config/spring-cache-3.2.xsd, http://www.springframework.org/schema/aop/spring-aop-3.0.xsd=org/springframework/aop/config/spring-aop-3.0.xsd, http://www.springframework.org/schema/task/spring-task-3.1.xsd=org/springframework/scheduling/config/spring-task-3.1.xsd, http://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop-2.0.xsd, http://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd, http://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.2.xsd, http://www.springframework.org/schema/jee/spring-jee-2.5.xsd=org/springframework/ejb/config/spring-jee-2.5.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd=org/springframework/jdbc/config/spring-jdbc-3.1.xsd, http://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd, http://www.springframework.org/schema/jee/spring-jee-3.1.xsd=org/springframework/ejb/config/spring-jee-3.1.xsd, http://www.springframework.org/schema/aop/spring-aop.xsd=org/springframework/aop/config/spring-aop-3.2.xsd, http://www.springframework.org/schema/context/spring-context-3.2.xsd=org/springframework/context/config/spring-context-3.2.xsd, http://www.springframework.org/schema/tx/spring-tx-3.2.xsd=org/springframework/transaction/config/spring-tx-3.2.xsd, http://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd, http://www.springframework.org/schema/util/spring-util-3.2.xsd=org/springframework/beans/factory/xml/spring-util-3.2.xsd, http://www.springframework.org/schema/lang/spring-lang-3.2.xsd=org/springframework/scripting/config/spring-lang-3.2.xsd, http://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd, http://www.springframework.org/schema/cache/spring-cache-3.2.xsd=org/springframework/cache/config/spring-cache-3.2.xsd, http://www.springframework.org/schema/task/spring-task-3.0.xsd=org/springframework/scheduling/config/spring-task-3.0.xsd, http://mybatis.org/schema/mybatis-spring.xsd=org/mybatis/spring/config/mybatis-spring-1.2.xsd, http://www.springframework.org/schema/tx/spring-tx-2.5.xsd=org/springframework/transaction/config/spring-tx-2.5.xsd, http://www.springframework.org/schema/context/spring-context-2.5.xsd=org/springframework/context/config/spring-context-2.5.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd=org/springframework/jdbc/config/spring-jdbc-3.0.xsd, http://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd, http://www.springframework.org/schema/lang/spring-lang.xsd=org/springframework/scripting/config/spring-lang-3.2.xsd, http://www.springframework.org/schema/tx/spring-tx.xsd=org/springframework/transaction/config/spring-tx-3.2.xsd, http://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd, http://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd, http://www.springframework.org/schema/lang/spring-lang-2.5.xsd=org/springframework/scripting/config/spring-lang-2.5.xsd, http://www.springframework.org/schema/aop/spring-aop-3.2.xsd=org/springframework/aop/config/spring-aop-3.2.xsd, http://www.springframework.org/schema/jee/spring-jee-3.0.xsd=org/springframework/ejb/config/spring-jee-3.0.xsd, http://www.springframework.org/schema/jee/spring-jee-2.0.xsd=org/springframework/ejb/config/spring-jee-2.0.xsd, http://www.springframework.org/schema/context/spring-context-3.1.xsd=org/springframework/context/config/spring-context-3.1.xsd, http://www.springframework.org/schema/tx/spring-tx-3.1.xsd=org/springframework/transaction/config/spring-tx-3.1.xsd, http://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd, http://www.springframework.org/schema/lang/spring-lang-3.1.xsd=org/springframework/scripting/config/spring-lang-3.1.xsd, http://www.springframework.org/schema/cache/spring-cache-3.1.xsd=org/springframework/cache/config/spring-cache-3.1.xsd, http://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-3.2.xsd, http://www.springframework.org/schema/jee/spring-jee.xsd=org/springframework/ejb/config/spring-jee-3.2.xsd, http://www.springframework.org/schema/aop/spring-aop-2.5.xsd=org/springframework/aop/config/spring-aop-2.5.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc.xsd=org/springframework/jdbc/config/spring-jdbc-3.2.xsd, http://www.springframework.org/schema/beans/spring-beans-3.2.xsd=org/springframework/beans/factory/xml/spring-beans-3.2.xsd, http://www.springframework.org/schema/tx/spring-tx-2.0.xsd=org/springframework/transaction/config/spring-tx-2.0.xsd, http://www.springframework.org/schema/aop/spring-aop-3.1.xsd=org/springframework/aop/config/spring-aop-3.1.xsd, http://www.springframework.org/schema/task/spring-task-3.2.xsd=org/springframework/scheduling/config/spring-task-3.2.xsd, http://www.springframework.org/schema/context/spring-context-3.0.xsd=org/springframework/context/config/spring-context-3.0.xsd, http://www.springframework.org/schema/tx/spring-tx-3.0.xsd=org/springframework/transaction/config/spring-tx-3.0.xsd, http://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-3.2.xsd, http://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd, http://www.springframework.org/schema/lang/spring-lang-3.0.xsd=org/springframework/scripting/config/spring-lang-3.0.xsd, http://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd, http://www.springframework.org/schema/lang/spring-lang-2.0.xsd=org/springframework/scripting/config/spring-lang-2.0.xsd, http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd=org/springframework/jdbc/config/spring-jdbc-3.2.xsd, http://www.springframework.org/schema/tool/spring-tool-3.2.xsd=org/springframework/beans/factory/xml/spring-tool-3.2.xsd, http://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd}
[framework] 2016-08-15 09:39:30,277 - org.springframework.beans.factory.xml.PluggableSchemaResolver -276  [main] DEBUG org.springframework.beans.factory.xml.PluggableSchemaResolver  - Found XML schema [http://www.springframework.org/schema/beans/spring-beans-3.0.xsd] in classpath: org/springframework/beans/factory/xml/spring-beans-3.0.xsd
[framework] 2016-08-15 09:39:30,340 - org.springframework.beans.factory.xml.PluggableSchemaResolver -339  [main] DEBUG org.springframework.beans.factory.xml.PluggableSchemaResolver  - Trying to resolve XML entity with public id [null] and system id [http://www.springframework.org/schema/context/spring-context-3.0.xsd]
[framework] 2016-08-15 09:39:30,341 - org.springframework.beans.factory.xml.PluggableSchemaResolver -340  [main] DEBUG org.springframework.beans.factory.xml.PluggableSchemaResolver  - Found XML schema [http://www.springframework.org/schema/context/spring-context-3.0.xsd] in classpath: org/springframework/context/config/spring-context-3.0.xsd
[framework] 2016-08-15 09:39:30,348 - org.springframework.beans.factory.xml.PluggableSchemaResolver -347  [main] DEBUG org.springframework.beans.factory.xml.PluggableSchemaResolver  - Trying to resolve XML entity with public id [null] and system id [http://www.springframework.org/schema/tool/spring-tool-3.0.xsd]
[framework] 2016-08-15 09:39:30,349 - org.springframework.beans.factory.xml.PluggableSchemaResolver -348  [main] DEBUG org.springframework.beans.factory.xml.PluggableSchemaResolver  - Found XML schema [http://www.springframework.org/schema/tool/spring-tool-3.0.xsd] in classpath: org/springframework/beans/factory/xml/spring-tool-3.0.xsd

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext-commons.xml]; nested exception is java.io.UTFDataFormatException: Invalid byte 3 of 3-byte UTF-8 sequence.

    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:408)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
    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:130)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at manager.admin.AdminUserDaoTest.testFindAdminUsersByAdminId(AdminUserDaoTest.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.io.UTFDataFormatException: Invalid byte 3 of 3-byte UTF-8 sequence.
    at org.apache.xerces.impl.io.UTF8Reader.invalidByte(Unknown Source)
    at org.apache.xerces.impl.io.UTF8Reader.read(Unknown Source)
    at org.apache.xerces.impl.XMLEntityScanner.load(Unknown Source)
    at org.apache.xerces.impl.XMLEntityScanner.peekChar(Unknown Source)
    at org.apache.xerces.impl.XMLScanner.scanComment(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanComment(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
    ... 41 more

Process finished with exit code -1

改成

org.xml.sax.SAXParseException: Content is not allowed in trailing section

Google了一下,原因大致如下:

2、或者把xml打开另存的时候把字符集改为UTF-8后保存
或改程序
复制代码 代码如下:
 SAXReader reader = new SAXReader(); 
  org.dom4j.Document document = reader.read("D:ha.xml"); 
  OutputFormat of = new OutputFormat(); 
  of.setEncoding("UTF-8"); //改变编码方式 
XMLWriter writer = new XMLWriter(new FileWriter "d:dom4j.xml"), of);  

把先要解析和字符串trim()一下即可解决问题。

(a) The file was intended to be UTF-8, but was incorrectly encoded;
(b) The file is in some other encoding such as iso-8859-1, but has no XML
8455新葡萄娱乐,declaration describing its encoding, so UTF-8 has been assumed by the XML
parser.
(c) The file has been transcoded in transit, that is, it declares its
encoding to be UTF-8 in its XML declaration, but some software that doesn't
understand XML changed its encoding to something else, without changing the
XML declaration.