如何在spring配置文件中使用util:list

时间:2014-03-04 07:43:03

标签: java spring spring-mvc

我正在尝试使用spring的unmarshaller来自动将请求体从xml解组到一个对象。但是我没有收到错误util prfeix unbind。您能否告诉我如何使用util:list?我在哪里可以找到util:list的参考。

我确实发现官方文档在>中遗漏了</property,我在配置中对此进行了更正。

我发现只需编写代码就更令人沮丧了。

<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
    <property name="messageConverters">
        <util:list id="beanList">
            <ref bean="stringHttpMessageConverter"/>
            <ref bean="marshallingHttpMessageConverter"/>
        </util:list>
    </property
</bean>

<bean id="stringHttpMessageConverter"
        class="org.springframework.http.converter.StringHttpMessageConverter"/>

<bean id="marshallingHttpMessageConverter"
        class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
    <property name="marshaller" ref="castorMarshaller" />
    <property name="unmarshaller" ref="castorMarshaller" />
</bean>

<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller"/>

1 个答案:

答案 0 :(得分:1)

您需要声明util命名空间; e.g:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">