使用带有java路由的camel jaxb时出错

时间:2017-03-26 15:07:24

标签: jaxb apache-camel

根据Camel文档,我创建了JaxbDataFormat(文档中的示例代码虽然使用了不存在的构造函数?)

@Override
public void configure() throws Exception {

    JaxbDataFormat jaxbDataFormat = new JaxbDataFormat();
    jaxbDataFormat.setContextPath("somepackage");

我有pom-dependency

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jaxb</artifactId>
        <version>2.18.3</version>
    </dependency>

不起作用:“ConvertBody ...因为数据格式'jaxb'无法创建。”

有人可以举例说明jaxb转换应该如何与Camel一起使用。我有Camel in Action 2ed,但那里的例子使用XML-definde路由。使用XML,过程看起来很简单 - 但我并不是非常热衷于使用xml作为编程语言;)

使用java 8。

............

线程中的异常“CamelMainRunController”java.lang.RuntimeException:org.apache.camel.FailedToCreateRouteException:无法在以下位置创建路由route2:&gt;&gt;&gt; Marshal [org.apache.camel.model.dataformat.JaxbDataFormat@57d7f108]&lt;&lt;&lt;在路线中:路线(路线2)[[来自[activemq:gateway.queue]] - &gt; [OnException ...因为数据格式'jaxb'无法创建。确保数据格式有效,并且类路径中存在关联的Camel组件     在org.apache.camel.spring.boot.CamelSpringBootApplicationController.run(CamelSpringBootApplicationController.java:74)     在org.apache.camel.spring.boot.CamelMainRunController $ DaemonTask.run(CamelMainRunController.java:42)     在java.lang.Thread.run(Thread.java:745) 引起:org.apache.camel.FailedToCreateRouteException:无法在以下位置创建路由route2:&gt;&gt;&gt; Marshal [org.apache.camel.model.dataformat.JaxbDataFormat@57d7f108]&lt;&lt;&lt;在路线中:路线(路线2)[[来自[activemq:gateway.queue]] - &gt; [OnException ...因为数据格式'jaxb'无法创建。确保数据格式有效,并且类路径中存在关联的Camel组件     在org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1071)     at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:196)     at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:984)     at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3401)     at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3132)     at org.apache.camel.impl.DefaultCamelContext.access $ 000(DefaultCamelContext.java:183)     at org.apache.camel.impl.DefaultCamelContext $ 2.call(DefaultCamelContext.java:2961)     at org.apache.camel.impl.DefaultCamelContext $ 2.call(DefaultCamelContext.java:2957)     at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2980)     at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2957)     在org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)     at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2924)     在org.apache.camel.main.Main.doStart(Main.java:129)     在org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)     在org.apache.camel.main.MainSupport.run(MainSupport.java:138)     在org.apache.camel.spring.boot.CamelSpringBootApplicationController.run(CamelSpringBootApplicationController.java:69)     ......还有2个 引起:java.lang.IllegalArgumentException:无法创建数据格式'jaxb'。确保数据格式有效,并且类路径中存在关联的Camel组件     at org.apache.camel.model.DataFormatDefinition.getDataFormat(DataFormatDefinition.java:107)     at org.apache.camel.model.DataFormatDefinition.getDataFormat(DataFormatDefinition.java:88)     在org.apache.camel.model.MarshalDefinition.createProcessor(MarshalDefinition.java:177)     在org.apache.camel.model.ProcessorDefinition.makeProcessorImpl(ProcessorDefinition.java:545)     在org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:506)     at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:222)     在org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1068)     ......还有17个

1 个答案:

答案 0 :(得分:3)

添加到pom

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jaxb-starter</artifactId>
        <version>2.23.1</version>
    </dependency>

并更新项目