我有一个应用程序,我在其中使用Spring启动MVC和驼峰。 下面是我正在运行的代码。
@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);
}
如果我使用上面的@ImportResource注释(目前已注释),则骆驼路线不会启动。
例如下面没有注释。
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)
在我启用注释后,下面有两个日志行。
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)
当我启用注释时,知道为什么这不起作用?注 - 总路线为零。
请注意我需要XML配置,因为我打算稍后在那里定义bean和属性。
以下是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>
答案 0 :(得分:3)
在与OP讨论之后我们发现,问题在于将Apache Camel依赖项与Spring Boot 2.0.x依赖项混合在一起。
由于Spring Boot 2.0.x中的一些API更改,Apache Camel尚不支持Spring Boot 2.0。
Apache Camel 2.21.0 release notes
中也提到了这一点此版本仅支持Spring Boot 1.5.x. Spring Boot 2.0.x的支持将在Camel 2.22版本中推出,计划于2018年初夏使用。
目前解决方案是将Spring Boot 1.5.x与Apache Camel一起使用。
具有实际兼容依赖关系的POM:
<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>