我已经在 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/