I am using camel-spring-boot-starter version 3.22.1. The spring-boot application is started but the CamelContext is null and its causing the issue for the "configure()" method. Below are my code samples, any suggestion would be really helpful. What's I'm missing.
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=".0.0" xmlns:xsi=""
xsi:schemaLocation=".0.0 .0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>.mkb.camel.example</groupId>
<artifactId>demo-camel-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo-camel-test</name>
<description>demo-camel-test</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>3.22.1</version>
<exclusions>
<exclusion>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>.apache.camel</groupId>
<artifactId>camel-http</artifactId>
<version>3.22.1</version>
</dependency>
<dependency>
<groupId>.apache.camel</groupId>
<artifactId>camel-core-model</artifactId>
<version>3.22.1</version>
</dependency>
<dependency>
<groupId>.apache.camel</groupId>
<artifactId>camel-base64</artifactId>
<version>3.22.1</version>
</dependency>
<dependency>
<groupId>.apache.camel</groupId>
<artifactId>camel-azure-storage-blob</artifactId>
<version>3.22.1</version>
</dependency>
<dependency>
<groupId>.apache.camel</groupId>
<artifactId>camel-aws2-s3</artifactId>
<version>3.22.1</version>
</dependency>
<dependency>
<groupId>.apache.camel</groupId>
<artifactId>camel-google-storage</artifactId>
<version>3.22.1</version>
</dependency>
<dependency>
<groupId>.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>3.22.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I am using camel-spring-boot-starter version 3.22.1. The spring-boot application is started but the CamelContext is null and its causing the issue for the "configure()" method. Below are my code samples, any suggestion would be really helpful. What's I'm missing.
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache./POM/4.0.0" xmlns:xsi="http://www.w3./2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache./POM/4.0.0 https://maven.apache./xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>.mkb.camel.example</groupId>
<artifactId>demo-camel-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo-camel-test</name>
<description>demo-camel-test</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>3.22.1</version>
<exclusions>
<exclusion>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>.apache.camel</groupId>
<artifactId>camel-http</artifactId>
<version>3.22.1</version>
</dependency>
<dependency>
<groupId>.apache.camel</groupId>
<artifactId>camel-core-model</artifactId>
<version>3.22.1</version>
</dependency>
<dependency>
<groupId>.apache.camel</groupId>
<artifactId>camel-base64</artifactId>
<version>3.22.1</version>
</dependency>
<dependency>
<groupId>.apache.camel</groupId>
<artifactId>camel-azure-storage-blob</artifactId>
<version>3.22.1</version>
</dependency>
<dependency>
<groupId>.apache.camel</groupId>
<artifactId>camel-aws2-s3</artifactId>
<version>3.22.1</version>
</dependency>
<dependency>
<groupId>.apache.camel</groupId>
<artifactId>camel-google-storage</artifactId>
<version>3.22.1</version>
</dependency>
<dependency>
<groupId>.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>3.22.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
MyTestRoute.java
package .mkb.camel.example.democameltest;
import .apache.camel.builder.RouteBuilder;
import .springframework.stereotype.Component;
@Component
public class MyTestRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer:foo?period=1000")
.log("Hello Camel!");
}
}
DemoCamelTestApplication.java
package .mkb.camel.example.democameltest;
import .springframework.boot.SpringApplication;
import .springframework.boot.autoconfigure.SpringBootApplication;
import .springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackages=".mkb.camel.example.democameltest")
public class DemoCamelTestApplication {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(DemoCamelTestApplication.class, args);
}
}
Share
Improve this question
asked yesterday
JDGuideJDGuide
6,52512 gold badges51 silver badges66 bronze badges
1 Answer
Reset to default 0Try removing all dependency and keep only the below dependency.
<dependency>
<groupId>.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>
Keep the camel running by adding below configuration file
@Component
public class CamelKeepAlive implements ApplicationRunner {
private final CamelSpringBootApplicationController controller;
public CamelKeepAlive(CamelSpringBootApplicationController controller) {
this.controller = controller;
}
@Override
public void run(ApplicationArguments args) throws Exception {
controller.run();
}
}
Do not create camelContext bean manually now and also no need to add componentScan. Just the above two changes.