spring-bootmavenapache-camel

error apache camel in spring boot with file camel-routes.yml


i have application with apache camel into spring boot and the routes are configured into camel-routes.yml with 2 processor.

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

processor :

@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"

CONTROLLER :

@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";
    }
}

when I launch the application with eclipse I get the following error:

org.apache.camel.spring.boot.CamelSpringBootInitializationException: java.lang.IllegalArgumentException: Cannot find RoutesBuilderLoader in classpath supporting file extension: yml

do I have to create the configuration class?


Solution

  • Change the file extension from .yml to .yaml