如何解决Apache Camel中“创建路由失败route1异常”?

ttcibm8c  于 2023-08-05  发布在  Apache
关注(0)|答案(3)|浏览(193)

我是Apache Camel概念的新手。我试着用apache camel API编写示例代码,当我尝试运行代码时,我得到了以下异常。

有人能帮我解决这个问题吗?

下面是示例代码和一个异常,

  • 示例代码:*
CamelContext context = new DefaultCamelContext();
 context.addRoutes(new RouteBuilder() { 
  public void configure() {
    from("direct:start")
    .setHeader(Exchange.HTTP_URI,simple("`http://sample-host:8080/demo/get`"))
    .to("http://emptyhost");
  }
 });
 context.start();
 ProducerTemplate template = context.createProducerTemplate();
 System.out.println(template.requestBodyAndHeaders("direct:start", null, null,String.class));

字符串

  • 异常:*
Exception in thread "main" org.apache.camel.FailedToCreateRouteException: 
Failed to create route route1 at: 
    >>> To[`http://sample-host:8080/demo/get`] <<< 
in route: Route(route1)
    [[From[direct:start]] -> [`To[http://sample-host:8`…
because of 
    Failed to resolve endpoint: `http://sample-host:8080/demo/get`
due to: 
    No component found with scheme: http

dsekswqp

dsekswqp1#

缺少依赖项库。所以我添加了这些库并解决了我的问题。

watbbzwu

watbbzwu2#

我得到了同样的错误,DIS是由于使用最新的依赖项。所以使用旧的依赖项并尝试。

egdjgwm8

egdjgwm83#

使用后,这些问题得到解决,我能够得到回应。我使用下面的依赖关系。

<properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <camel.version>3.11.4</camel.version>
</properties>

<dependencies>
        <!-- https://mvnrepository.com/artifact/org.apache.camel/camel-core -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>${camel.version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.camel/camel-http -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-http</artifactId>
            <version>${camel.version}</version>
        </dependency>
</dependencies>

字符串

相关问题