Rest DSL route - не удалось запустить маршрут из-за того, что использование нескольких потребителей для одной и той же конечной точки запрещено - PullRequest
0 голосов
/ 17 апреля 2020

Я пытаюсь проработать пример для поддержки весенней загрузки. Приветственное приложение REST DSL на верблюде, когда я пытаюсь запустить приложение через весеннюю загрузку, я получаю следующее исключение:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.4.RELEASE:run (default-cli) on project helloworld-example: An exception occurred while running. null: InvocationTargetException: org.apache.camel.FailedToStartRouteException: Failed to start route route3 because of Multiple consumers for the same endpoint is not allowed: direct://hello -> [Help 1]

Из того, что я вижу и понимаю, я настроил только один маршрут, который связывает мой маршрут "/ hello" с компонентом, выполняющим метод.

Мой класс маршрута:

package my.project.route;

import my.project.model.ResponseObject;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestBindingMode;
import org.springframework.stereotype.Component;

@Component
public class MyRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        // configures REST DSL to use servlet component and in JSON mode
        restConfiguration()
                .component("servlet")
                .bindingMode(RestBindingMode.json);

        // REST DSL with a single GET /hello service
        rest()
                .get("/hello")
                .to("direct:hello");

        // route called from REST service that builds a response message
        from("direct:hello")
                .log("Hello World")
                .bean(this, "createResponse");
    }

    public ResponseObject createResponse() {
        ResponseObject response = new ResponseObject();
        response.setResponse("Hello World");
        response.setName("stack overflow");
        return response;
    }
}

Мой Код приложения

package my.project;

import org.apache.camel.component.servlet.CamelHttpTransportServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@SpringBootApplication
@Configuration
@ComponentScan("my.project")
public class Application {

    /**
     * A main method to start this application.
     */
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public ServletRegistrationBean camelServletRegistrationBean() {
        ServletRegistrationBean registration = new ServletRegistrationBean(new CamelHttpTransportServlet(),"/camel/*");
        registration.setName("CamelServlet");
        return registration;
    }

}

POM:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>my.project</groupId>
  <artifactId>helloworld-example</artifactId>
  <version>1.0-SNAPSHOT</version>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>

  <name>Fabric8 :: Quickstarts :: Spring-Boot :: Camel</name>
  <description>Spring Boot example running a Camel route</description>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>



    <!-- Fuse 6.3 GA version for Spring Boot -->
    <!--<spring-boot.version>1.4.1.RELEASE</spring-boot.version>-->
    <!-- Fuse 7 EA / GA version for Spring Boot -->
    <spring-boot.version>1.5.4.RELEASE</spring-boot.version>

    <maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
    <maven-surefire-plugin.version>2.18.1</maven-surefire-plugin.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <version>1.5.4.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
      <version>1.5.4.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-spring-boot-starter</artifactId>
      <version>2.25.1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-servlet-starter</artifactId>
      <version>2.25.1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-jackson-starter</artifactId>
      <version>2.25.1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-swagger-java-starter</artifactId>
      <version>2.25.1</version>
    </dependency>

  </dependencies>

  <build>
    <defaultGoal>spring-boot:run</defaultGoal>

    <plugins>

      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${maven-compiler-plugin.version}</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven-surefire-plugin.version}</version>
        <inherited>true</inherited>
        <configuration>
          <excludes>
            <exclude>**/*KT.java</exclude>
          </excludes>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${spring-boot.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>

  </build>

  <!-- used for adding maven repositories to download Fuse JARs -->
  <profiles>
    <profile>
      <id>fuse.repos</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>

      <repositories>
        <repository>
          <id>maven.central</id>
          <name>Maven Central</name>
          <url>https://repo1.maven.org/maven2</url>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
          </releases>
        </repository>


      </repositories>

      <pluginRepositories>
        <pluginRepository>
          <id>maven.central</id>
          <name>Maven Central</name>
          <url>https://repo1.maven.org/maven2</url>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
          </releases>
        </pluginRepository>

      </pluginRepositories>
    </profile>
  </profiles>

</project>

1 Ответ

0 голосов
/ 18 апреля 2020

Во-первых, вам не нужен компонент camelServletRegistrationBean() в классе Application. Это требуется только для верблюда 2.19 и ниже. Вместо этого добавьте camel.component.servlet.mapping.context-path=/* в файл application.properties.

Кроме того, вы можете избавиться от @ComponentScan. Поскольку у вас есть аннотация @Component на вашем маршруте, Spring автоматически добавит это в контекст.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...