如何处理像'<''&燃气轮机''&';在Spring3REST中编组/解编XML时

如何处理像'<''&燃气轮机''&';在Spring3REST中编组/解编XML时,xml,spring,rest,spring-mvc,unmarshalling,Xml,Spring,Rest,Spring Mvc,Unmarshalling,我正在使用SpringREST,在从Http请求中解组XML时遇到以下异常 例外情况: 异常:org.springframework.http.converter.httpmessagenetradableexception:无法读取[class com.sample.beans.Address];嵌套异常为org.springframework.oxm.UnmarshallingFailureException:JAXB unmarshalling异常;嵌套异常为javax.xml.bind.

我正在使用SpringREST,在从Http请求中解组XML时遇到以下异常

例外情况: 异常:org.springframework.http.converter.httpmessagenetradableexception:无法读取[class com.sample.beans.Address];嵌套异常为org.springframework.oxm.UnmarshallingFailureException:JAXB unmarshalling异常;嵌套异常为javax.xml.bind.UnmarshalException-带有链接异常:[org.xml.sax.SAXParseException:实体名称必须紧跟实体引用中的“&”。]

在请求XML中,我传递了像“&”这样的字符 例:安达曼和尼科巴

控制器类:

@RequestMapping(method=RequestMethod.POST,value="v1/createuser/{user}", headers="Content-Type=application/xml")
@ResponseStatus(HttpStatus.CREATED)
public ModelAndView createUser(@RequestBody Address address,@PathVariable("user") String owner,HttpServletRequest request,HttpServletResponse response){
//code to store the address and return response in the form of xml
}
Spring servlet xml:

<?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"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.1.xsd">


<context:component-scan base-package="com.samples.controller" />

<!-- To enable @RequestMapping process on type level and method level -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />

<!--  <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />-->
<bean id="methodHandler" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <list>
            <ref bean="marshallConverter"/>
        </list>
    </property>
</bean>
<bean id="marshallConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
        <property name="marshaller" ref="jaxb2Marshaller" />
        <property name="unmarshaller" ref="jaxb2Marshaller" />
        <property name="supportedMediaTypes" value="application/xml" />
    </bean>


    <bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="classesToBeBound">
            <list>
                <value>com.sample.beans.Address</value>
              </list>
        </property>
    </bean>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver" />

        <bean id="dsmPolicyRuleResponse" class="org.springframework.web.servlet.view.xml.MarshallingView">
                <constructor-arg ref="jaxb2Marshaller" />
        </bean>

</beans>

com.sample.beans.Address
但如果我通过了像安达曼和尼科巴这样的考试,我会感觉很好。
但我需要找到一种处理特殊字符的方法,如“&”、“>”、“通过为JAXB封送拆收器设置以下属性来完成:

Spring Bean configuration: 

<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshalle r">
    <description>
        The JAXB Marshaller is used by the sendToTargetRequest to (un)marshal XML to objects and vice-versa.
    </description>
    <property name="contextPath" value="xx.orders.types:xx.orders.functionalack"/>
    <property name="mtomEnabled" value="false"/>
    <property name="marshallerProperties">
        <map>
            <entry key="jaxb.encoding">
                <value>UTF-8</value>
            </entry>
        </map>
    </property>
</bean>
springbean配置:
sendToTargetRequest使用JAXB封送器将XML封送到对象,反之亦然。
UTF-8

但是在spring mvc中,spring将负责编组/解编。如何配置spring配置来进行Unicode编码?我已经更新了相应的bean配置。试试这个,确认一下