Reputation: 75
I have an application in which I am using Spring boot MVC and camel. below is the code that I am running.
@ComponentScan({"com.xyz.routes","com.xyz.web","com.xyz.security"})
@SpringBootApplication
//@ImportResource("classpath:META-INF/spring/camelContext.xml")
public class Application {
public static void main(String[] args) {
ApplicationContext applicationContext = SpringApplication.run(Application.class, args);
}
If I use @ImportResource annotation above (currently commented) the camel routes don't start.
For example below is without annotation.
INFO | 27 Apr 2018 15:26:31,149 | [main] org.apache.camel.spring.SpringCamelContext - Total 1 routes, of which 1 are started. | | | (DefaultCamelContext.java:2834)
INFO | 27 Apr 2018 15:26:31,150 | [main] org.apache.camel.spring.SpringCamelContext - Apache Camel 2.17.0 (CamelContext: camel-1) started in 0.255 seconds | | | (DefaultCamelContext.java:2835)
And below two log lines are after I enabled annotation.
INFO | 27 Apr 2018 15:30:56,755 | [main] org.apache.camel.spring.SpringCamelContext - Total 0 routes, of which 0 are started. | | | (DefaultCamelContext.java:2834)
INFO | 27 Apr 2018 15:30:56,755 | [main] org.apache.camel.spring.SpringCamelContext - Apache Camel 2.17.0 (CamelContext: mtmSender) started in 0.089 seconds | | | (DefaultCamelContext.java:2835)
Any idea why this is not working when I enable the annotation? Note - Total routes are zero.
Please note that I need XML config because I am planning to define beans and properties there later.
Below is the camelContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name="locations">
<list>
<value>${application-default.properties}</value>
<value>${application.properties}</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_NEVER" />
</bean>
<bean id="sampleBean" class="com.xyz.model.SampleBean" />
<camelContext xmlns="http://camel.apache.org/schema/spring" id="mtmSender">
<properties>
<property key="CamelLogDebugStreams" value="true"/>
</properties>
</camelContext>
</beans>
Upvotes: 4
Views: 3761
Reputation: 4919
After discussion with OP we have found, the problem was mixing Apache Camel dependencies with Spring Boot 2.0.x dependencies.
Because of some breaking API changes in Spring Boot 2.0.x, Apache Camel does not support Spring Boot 2.0 yet.
This is also mentioned in Apache Camel 2.21.0 release notes
This release supports only Spring Boot 1.5.x. Support for Spring Boot 2.0.x is coming in Camel version 2.22 which is planned for early summer 2018.
For now the solution is to use Spring Boot 1.5.x with Apache Camel.
POM with actual compatible dependencies:
<dependencyManagement>
<dependencies>
<!-- Spring Boot BOM -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.12.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Camel BOM -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-dependencies</artifactId>
<version>2.21.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Camel -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-stream-starter</artifactId>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.12.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Upvotes: 4