0
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:hsf="http://www.taobao.com/hsf"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.taobao.com/hsf http://www.taobao.com/hsf/hsf.xsd">

    <hsf:consumer id="fcAccountQueryService"
        interface="com.aliexpress.finance.open.fcaccount.share.service.FcAccountQueryService"
        version="1.0.0" group="DUBBO" />
</beans>

This is my xml file, but when I deploy, I got error Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 6 in XML document from class path resource [biz/consumer/services/spring_fc_account_services.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Invalid byte 2 of 2-byte UTF-8 sequence.. Why?

And the other xml line 6 is

<beans>
    <import resource="/consumer/services/spring_fc_account_services.xml" />
</beans>
Papershine
  • 4,995
  • 2
  • 24
  • 48
He Yuntao
  • 86
  • 11

3 Answers3

0

This means that the xml file is saved in some other format other than UTF-8

Try saving file in UTF-8 format

Try referring here and here for similar problem

Community
  • 1
  • 1
Ankur Singhal
  • 26,012
  • 16
  • 82
  • 116
0

There Might be some Special Characters which you are not able to see because the editor,terminal,gedit tools etc doesn't support that character.

Another way to handle the same exception what I found is

new String(bytes,"ISO-8859-1").getBytes("UTF-16");

If your contents are giving the SAXException: Invalid byte 2 of 2-byte UTF-8 sequence.

Mukesh Kumar
  • 317
  • 1
  • 5
  • 16
0

I try to save file in UTF-8 format and in ISO-8859-1, I get the error again. So it's not caused by encoding.
And I try to add the same xml file to other spring application, it works. I'm sure all the xml files are same.
Then I compared the two app's dependency. I found the app which worked well has a dependency of hsf.
In my xml file, I used http://www.taobao.com/hsf http://www.taobao.com/hsf/hsf.xsd xsd. So I add the hsf dependency to my pom.xml, all problems was solved, the app started successful!

Papershine
  • 4,995
  • 2
  • 24
  • 48
He Yuntao
  • 86
  • 11