簡體   English   中英

Spring XML中的Apache Camel路由定義並與SpringBoot一起運行

[英]Apache Camel route definition in Spring XML and run with SpringBoot

我已經在2個XML文件中定義了駱駝路線,並希望使用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);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM