java - Spring XML 中的 Apache Camel 路由定义并使用 SpringBoot 运行

标签 java spring-boot apache-camel

我已经在 2 个 XML 文件中定义了 Camel 路由,并且想使用 Spring Boot 组件运行该应用程序。

主要代码如下:

Object[] sources = {
    "META-INF/spring/propertiesContext.xml",
    "META-INF/spring/concurrent-route-context.xml"
};
ApplicationContext applicationContext = new SpringApplication(sources).run(args);
CamelSpringBootApplicationController applicationController = applicationContext
    .getBean(CamelSpringBootApplicationController.class);
    applicationController.blockMainThread();

但是,我在启动过程中遇到以下错误

2015-08-19 14:54:04.203 ERROR 13812 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at com.oocl.b2b.camel.spring.boot.test.ConcurrencyTest.testSpringBoot(ConcurrencyTest.java:44)
at com.oocl.b2b.camel.spring.boot.test.ConcurrencyTest.main(ConcurrencyTest.java:29)
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:183)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:156)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130)
... 6 common frames omitted

如果我使用“spring-boot-starter”而不是“spring-boot-starter-web”更新我的 pom.xml,我会遇到另一个异常

2015-08-19 15:02:06.930  INFO 4528 --- [           main] o.a.camel.spring.SpringCamelContext      : Apache Camel 2.15.2 (CamelContext: concurrent-route-context) started in 1.320 seconds
2015-08-19 15:02:06.932  INFO 4528 --- [           main] c.o.b.c.s.boot.test.ConcurrencyTest      : Started ConcurrencyTest in 2.615 seconds (JVM running for 2.867)
Exception in thread "main" 2015-08-19 15:02:06.933  INFO 4528 --- [       Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@142f024: startup date [Wed Aug 19 15:02:05 CST 2015]; root of context hierarchy
2015-08-19 15:02:06.934  INFO 4528 --- [       Thread-1] o.a.camel.spring.SpringCamelContext      : Apache Camel 2.15.2 (CamelContext: concurrent-route-context) is shutting down
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.apache.camel.spring.boot.CamelSpringBootApplicationController] is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:371)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:968)
    at com.oocl.b2b.camel.spring.boot.test.ConcurrencyTest.testSpringBoot(ConcurrencyTest.java:47)
    at com.oocl.b2b.camel.spring.boot.test.ConcurrencyTest.main(ConcurrencyTest.java:30)
2015-08-19 15:02:06.937  INFO 4528 --- [       Thread-1] o.a.camel.impl.DefaultShutdownStrategy   : Starting to graceful shutdown 4 routes (timeout 300 seconds)

如果我配置错误,有人可以提出建议吗?

最佳答案

我不知道您是否已找到解决方案,但请在您的应用程序类中尝试一下:

@Configuration
@EnableAutoConfiguration
public class TestSpringBootApplication
{
    public static void main(String... args)
    {
        (new SpringApplication("META-INF/spring/propertiesContext.xml",
                               "META-INF/spring/concurrent-route-context.xml")).run(args);
    }
}

关于java - Spring XML 中的 Apache Camel 路由定义并使用 SpringBoot 运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32088669/

相关文章:

java - 包括 spring boot 端点路径变量作为度量维度

apache-camel - 简单表达语言 : how to get the ${routeId} in Apache Camel 2. 10

java - 有没有一种方法可以在不使用 Camel 中的 .bean 关键字的情况下在我的路由中 Autowiring 一个 bean?

java - 如何使用 Camel 写出文件并返回文件名?

java - android studio,如何保存,更改数据

java - 使用 java.applet 类在 Java 中播放声音

java - 无法使用配置的公钥验证 RSA 签名。签名长度不正确: got 255 but was expecting 256

java - 枚举实例内的异常处理

spring-boot - Consul 键值对用于 Spring-boot 中的配置

java - 保存或检索以前的 Camel 交换体