gpt4 book ai didi

spring-boot - 如何? - 带有 Spring Boot 和 XML 配置的 Apache Camel

转载 作者:行者123 更新时间:2023-12-04 02:29:29 24 4
gpt4 key购买 nike

我有一个应用程序,我在其中使用 Spring Boot MVC 和 Camel 。
下面是我正在运行的代码。

@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 注释(当前已注释),则 Camel 路线不会启动。

例如下面没有注释。
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>

最佳答案

在与 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中也有提到

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.



目前的解决方案是将 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>

关于spring-boot - 如何? - 带有 Spring Boot 和 XML 配置的 Apache Camel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50069238/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com