我正在尝试配置Jaxb2Marshaller
,如下所示:
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.test.response1.ResponseType1</value>
<value>com.test.response2.ResponseType2</value>
<value>com.test.request.Request</value>
</list>
</property>
</bean>
它有效。
混淆是classesToBound
问题中提及的类的顺序吗?
如果我将其更改为:
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.test.request.Request</value>
<value>com.test.response1.ResponseType1</value>
<value>com.test.response2.ResponseType2</value>
</list>
</property>
</bean>
一切都完全一样,我得到以下异常:
org.springframework.beans.TypeMismatchException: Failed to convert value of type 'com.test.response2.ResponseType2' to required type 'com.test.request.Request'
正在使用的spring
版本为:3.1.2.RELEASE
有人可以帮忙吗?
答案 0 :(得分:0)
除非在Spring 3.1.0和3.1.2之间发生了某些变化,否则如果您正在处理JAXB生成的类,则顺序无关紧要。如果您手动创建/注释对象,那可能是另一个故事 - 也许如果您发布它们,我们可以提供帮助。另外,我强烈建议使用另一种机制,使用Jaxb2Marshaller
或contextPaths
属性将packagesToScan
指向要编组的类。请记住,contextPath
/ contextPaths
需要JAXB编译器生成的ObjectFactory
类。