Spring Boot 中的 apache Camel 错误,文件camel-routes.yml

问题描述 投票:0回答:1

我在 Spring Boot 中使用了 apache Camel 的应用程序,并且路由被配置到具有 2 个处理器的 Camel-routes.yml 中。

pom:

<properties>
    <java-version>17</java-version>
    <spring-boot.version>3.3.4</spring-boot.version>
    <camel.version>4.8.0</camel.version>
  </properties>
  <dependencies>
        <!-- Spring Boot Starter -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
      <version>${spring-boot.version}</version>
    </dependency>
    
    <!-- Spring Boot Starter for RESTful API -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <version>${spring-boot.version}</version>
    </dependency>
    
    <!-- Camel Spring Boot Starter for auto-configuration -->
    <dependency>
      <groupId>org.apache.camel.springboot</groupId>
      <artifactId>camel-spring-boot-starter</artifactId>
      <version>${camel.version}</version>
    </dependency>
    
    <!-- Camel YAML DSL for YAML route configuration -->
    <dependency>
      <groupId>org.apache.camel.springboot</groupId>
      <artifactId>camel-yaml-dsl-starter</artifactId>
      <version>${camel.version}</version>
    </dependency>
    
     <!-- Camel Stream for stream:out -->
    <dependency> 
      <groupId>org.apache.camel</groupId> 
      <artifactId>camel-stream</artifactId> 
      <version>${camel.version}</version> 
    </dependency>
    </dependencies>
   <build>
     <plugins> 
       <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
      <version>${spring-boot.version}</version>
       </plugin> 
    </plugins>
   </build>

application.yml

camel:
  springboot:
    routes-include-pattern: classpath:camel-routes.yml

处理器:

@Component("myFirstProcessor")
public class MyFirstProcessor implements Processor {
    
    public MyFirstProcessor() {
        System.out.println("myFirst processor istanziato");
    
    }   
    @Override
    public void process(Exchange exchange) throws Exception {
         System.out.println("myFirst Processor eseguito");
    }

}
@Component("mySecondProcessor")
public class MySecondProcessor implements Processor{
    
    public MySecondProcessor() {
        System.out.println("mySecond Processor istanziato");
    }

    @Override
    public void process(Exchange exchange) throws Exception {
        System.out.println("mySecond Processor eseguito");
    }

}

camel-routes.yml:

- from:
    uri: "direct:start"
    steps:
      - log: 
          message: "Messaggio ricevuto corretamente su direct:start"        
      - process:
          ref: "myFirstProcessor"
      - log: 
          message: "Passato attraverso myFirstProcessor"
      - process:
          ref: "mySecondProcessor"
      - log:
          message: "Passato attraverso mySecondProcessor"
      - to: 
          uri: "stream:out"

控制器:

@RestController
@RequestMapping("/api")
public class CamelController {

    private ProducerTemplate producerTemplate;
    
    public CamelController(ProducerTemplate producerTemplate) {
        this.producerTemplate = producerTemplate;
    }

    @GetMapping("/startRoute")
    public String startRoute() {
         producerTemplate.sendBody("direct:start", "Messaggio di prova");
         return "Messaggio inviato a direct:start";
    }
}

当我使用 Eclipse 启动应用程序时,出现以下错误:

org.apache.camel.spring.boot.CamelSpringBootInitializationException:java.lang.IllegalArgumentException:在支持文件扩展名的类路径中找不到RoutesBuilderLoader:yml

我必须创建配置类吗?

spring-boot maven apache-camel
1个回答
0
投票

将文件扩展名从 .yml 更改为 .yaml

© www.soinside.com 2019 - 2024. All rights reserved.