为Spring集成Web服务配置application / xml媒体类型的restful service请求

时间:2015-01-13 05:43:52

标签: spring-integration

使用spring集成为某些项目需求开发webservice以满足application/xml媒体类型的restful请求,但在部署Web应用程序时遇到以下异常:

Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: org.springframework.beans.NotWritablePropertyException: Invalid property 'componentName' of bean class [org.springframework.oxm.jaxb.Jaxb2Marshaller]: Bean property 'componentName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?. Please see server.log for more details.   

下面是使用媒体类型application / xml来处理Web请求的示例配置:

<int:channel id="xmlServiceImplChannel" />
<int:channel id="xmlServiceReqImplChannel" />

<int-http:inbound-gateway request-channel="xmlServiceImplChannel"
    supported-methods="POST" path="/xmlServiceImplReq"/>


<!-- this is require to enrich the header to handle the content-type of 
    type "application/xml" -->
<int:header-enricher input-channel="xmlServiceImplChannel"
    output-channel="xmlServiceReqImplChannel">
    <int:header name="content-type" value="application/xml"></int:header>
</int:header-enricher>

<int:chain input-channel="xmlServiceReqImplChannel">


<oxm:jaxb2-marshaller id="xmlMarshaller" context-path="com.xyz.channel.model"></oxm:jaxb2-marshaller>

<int:service-activator>
    <bean class="com.xyz.channel.model.serviceImpl.xmlServiceImpl"><constructor-arg ref="xmlServiceType"></constructor-arg></bean>
</int:service-activator>

<oxm:jaxb2-marshaller id="xmlMarshaller" context-path="com.xyz.channel.model"></oxm:jaxb2-marshaller>

</int:chain>

如果我错过了一些配置,请告诉我。

1 个答案:

答案 0 :(得分:0)

您尝试在<oxm:jaxb2-marshaller>中使用<chain>但是无法完成的问题,因为只有MessageHandler实施可以用作<bean>那里。

为了您的目的,您应该使用<int-xml:marshalling-transformer>并将该顶级xmlMarshaller注入<chain>内的该组件:

<oxm:jaxb2-marshaller id="xmlMarshaller" context-path="com.xyz.channel.model"></oxm:jaxb2-marshaller>

<int:chain input-channel="xmlServiceReqImplChannel">
   <si-xml:marshalling-transformer marshaller="xmlMarshaller" /> 
   <int:service-activator>
      <bean class="com.xyz.channel.model.serviceImpl.xmlServiceImpl"><constructor-arg     ref="xmlServiceType"></constructor-arg></bean>
   </int:service-activator>

</int:chain>

从另一方面来看,我不清楚在<service-activator>之后使用第二个编组的原因是什么......