2

我正在使用 Apache Camel 的 Spring Remoting 版本 2.11.0。我的 beans.xml 中有以下内容:

<camel:camelContext id="camel-client">
    <camel:dataFormats>
        <camel:jaxb contextPath="path.to.my.jaxb.index"/>
    </camel:dataFormats>
</camel:camelContext>

<camel:proxy
    id="myProxy"
    serviceInterface="path.to.my.service.MyService"
    serviceUrl="jms:queue:myQueue" camelContextId="camel-client"/>

默认情况下,camel:proxy 使用对象序列化,但我想改用 JAXB。这可能吗?我使用 ProducerTemplate 在 JAXB 上运行这种模式,但是当我切换到使用 camel:proxy 时,我得到了 NotSerializableException。

生产者模板通过 camel:camelContext 标签创建,并通过 Spring 注入:

@ContextConfiguration(locations={"beans.xml"})
public class MyTest extends AbstractJunit4SpringContextTests {

    @Autowired ProducerTemplate producerTemplate;  // this comes from <camel:camelContext>
    @Autowired MyService myService;  // this comes from <camel:proxy>

    @Test
    public void testMyService() {
        MyRequest myRequest = new MyRequest();

        // This correctly performs the JAXB serialization
        MyResponse response = producerTemplate.requestBody("jms:queue:myQueue", myRequest, MyResponse.class);

        // This still does Object serialization (and fails accordingly)
        response = myService.getResponse(myRequest);
    }
}
4

0 回答 0