如何通过XML在Spring bean中设置Jaxb2Marshaller XmlAdapter列表?

时间:2011-10-11 00:03:52

标签: xml spring jaxb spring-ws jaxb2

我正在尝试在Spring-WS中定义一个Jaxb2Marshaller bean,以使用扩展XmlAdapter的自定义适配器。我在XML文件中有以下内容:

<bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="classesToBeBound">
        <list>
            <!-- various classes to be bound... -->
        </list>
    </property>
    <property name="schema" value="myschema.xsd" />
    <property name="adapters">
        <list>
            <value>com.lmig.am.claims.clip.ContactAdapter</value>
        </list>
    </property>
</bean>

但是,我收到以下错误:

Cannot convert value of type [java.lang.String] to required type [javax.xml.bind.annotation.adapters.XmlAdapter] for property 'adapters[0]': no matching editors or conversion strategy found

任何想法我做错了什么?谢谢!

1 个答案:

答案 0 :(得分:7)

adapters属性需要一个XMLAdapter对象数组而不是Classes。所以正确的配置如下。

<property name="adapters">
   <list>
         <bean class="com.lmig.am.claims.clip.ContactAdapter"/>
   </list>
</property>