admin管理员组

文章数量:1295636

I am trying to expose a REST API from Apache Camel project running on Spring Boot.

I am following the instructions here - .html#_components_supporting_rest_dsl

I selected the platform HTTP component, since the document mentions this:

The Platform HTTP is used to allow Camel to use the existing HTTP server from the runtime. For example, when running Camel on Spring Boot, Quarkus, or other runtimes.

I added the following maven dependencies to the project.

    <dependency>
      <groupId>.apache.camel.springboot</groupId>
      <artifactId>camel-rest-starter</artifactId>
      <version>4.6.0</version>
    </dependency>
    <dependency>
      <groupId>.apache.camel.springboot</groupId>
      <artifactId>camel-platform-http-starter</artifactId>
      <version>4.6.0</version>
    </dependency>

I added a simple REST Route.

@Component
public class RestAPIRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {

        from("rest:get:hello")
                .transform().constant("Hello World");
    }
}

When I start the app, I get the following error:

.apache.camel.FailedToStartRouteException: Failed to start route route1 because of Cannot find RestConsumerFactory in Registry or as a Component to use
.....
Caused by: java.lang.IllegalStateException: Cannot find RestConsumerFactory in Registry or as a Component to use
    at .apache.camelponent.rest.RestEndpoint.createConsumer(RestEndpoint.java:601) ~[camel-rest-4.6.0.jar:4.6.0]
    at .apache.camel.impl.engine.DefaultRoute.gatherRootServices(DefaultRoute.java:670) ~[camel-base-engine-4.6.0.jar:4.6.0]
    at .apache.camel.impl.engine.DefaultRoute.gatherServices(DefaultRoute.java:654) ~[camel-base-engine-4.6.0.jar:4.6.0]
    at .apache.camel.impl.engine.DefaultRoute.initializeServices(DefaultRoute.java:225) ~[camel-base-engine-4.6.0.jar:4.6.0]
    at .apache.camel.impl.engine.RouteService.doSetup(RouteService.java:150) ~[camel-base-engine-4.6.0.jar:4.6.0]
    at .apache.camel.impl.engine.RouteService.setUp(RouteService.java:129) ~[camel-base-engine-4.6.0.jar:4.6.0]
    ... 22 common frames omitted

What additional configuration is needed for getting started with this REST API?

I am trying to expose a REST API from Apache Camel project running on Spring Boot.

I am following the instructions here - https://camel.apache./manual/rest-dsl.html#_components_supporting_rest_dsl

I selected the platform HTTP component, since the document mentions this:

The Platform HTTP is used to allow Camel to use the existing HTTP server from the runtime. For example, when running Camel on Spring Boot, Quarkus, or other runtimes.

I added the following maven dependencies to the project.

    <dependency>
      <groupId>.apache.camel.springboot</groupId>
      <artifactId>camel-rest-starter</artifactId>
      <version>4.6.0</version>
    </dependency>
    <dependency>
      <groupId>.apache.camel.springboot</groupId>
      <artifactId>camel-platform-http-starter</artifactId>
      <version>4.6.0</version>
    </dependency>

I added a simple REST Route.

@Component
public class RestAPIRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {

        from("rest:get:hello")
                .transform().constant("Hello World");
    }
}

When I start the app, I get the following error:

.apache.camel.FailedToStartRouteException: Failed to start route route1 because of Cannot find RestConsumerFactory in Registry or as a Component to use
.....
Caused by: java.lang.IllegalStateException: Cannot find RestConsumerFactory in Registry or as a Component to use
    at .apache.camelponent.rest.RestEndpoint.createConsumer(RestEndpoint.java:601) ~[camel-rest-4.6.0.jar:4.6.0]
    at .apache.camel.impl.engine.DefaultRoute.gatherRootServices(DefaultRoute.java:670) ~[camel-base-engine-4.6.0.jar:4.6.0]
    at .apache.camel.impl.engine.DefaultRoute.gatherServices(DefaultRoute.java:654) ~[camel-base-engine-4.6.0.jar:4.6.0]
    at .apache.camel.impl.engine.DefaultRoute.initializeServices(DefaultRoute.java:225) ~[camel-base-engine-4.6.0.jar:4.6.0]
    at .apache.camel.impl.engine.RouteService.doSetup(RouteService.java:150) ~[camel-base-engine-4.6.0.jar:4.6.0]
    at .apache.camel.impl.engine.RouteService.setUp(RouteService.java:129) ~[camel-base-engine-4.6.0.jar:4.6.0]
    ... 22 common frames omitted

What additional configuration is needed for getting started with this REST API?

Share asked Feb 12 at 3:28 ShankarShankar 2,8353 gold badges30 silver badges58 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I found that this above configuration assumes that the Spring MVC web server is running.

Source: https://github/apache/camel-spring-boot-examples/blob/main/platform-http/pom.xml

Add the following to the configuration to start the embedded web server, which is the platform http that Camel needs.

<dependency>
      <groupId>.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

本文标签: