Apache骆驼路线未被识别

时间:2016-08-15 03:38:59

标签: java spring-boot apache-camel

我有一个春季启动应用程序,我正在添加一个骆驼路线。定义路由的类扩展了FatJarRouter,并使用@Component进行注释。当应用程序作为spring boot应用程序运行时,路由无法识别。但是如果我使用@SpringBootApplication注释在主类中编写路由,则会识别路由。这是它在日志中的显示方式:

o.a.camel.spring.SpringCamelContext:共有0条路由,其中​​0条已启动。 o.a.camel.spring.SpringCamelContext:Apache Camel 2.17.2(CamelContext:camel-4)在0.026秒内启动

带路由的方法也使用覆盖注释为:

@Override
public void configure()  throws Exception{
from("file:\\input").to("file:\\output");
}

请告诉我如何在将其写为单独的课程时识别路线,而不是在主要课程中。有什么遗漏。

2 个答案:

答案 0 :(得分:0)

来自骆驼常见问题解答文档:

http://camel.apache.org/how-do-i-name-my-routes.html

from("direct:start").routeId("myRoute").to("mock:bar");

对于0路线,请参阅Miloš Milivojević提供的答案。

答案 1 :(得分:0)

今天遇到了同样的问题。将@ComponentScan和servlet注册放在配置类中对我来说很有效。

@SpringBootApplication
@Configuration
@ComponentScan("com.camel.practice")
    public class ApplicationMain {
    
        public static void main(String[] args) {
            SpringApplication.run(ApplicationMain.class, args);
        }
        @Bean
        public ServletRegistrationBean<CamelHttpTransportServlet> camelServletRegistrationBean() {
            ServletRegistrationBean<CamelHttpTransportServlet> registration = 
                    new ServletRegistrationBean<CamelHttpTransportServlet>(new CamelHttpTransportServlet(), "/*");
            registration.setName("CamelServlet");
            return registration;
        }