【问题标题】:Apache camel copy file between directories目录之间的Apache骆驼复制文件
【发布时间】:2021-07-21 21:56:44
【问题描述】:

我是 apache camel 和 spring boot 的新手。我正在编写一个应用程序,我需要将文件从文件夹传输到 jms 队列。但在此之前,我试图将文件从一个文件夹传输到另一个文件夹,但没有发生。在将应用程序作为 Spring Boot 应用程序运行时,将创建输入文件夹。如果将文件粘贴到此文件夹中,则不会形成目标文件夹,并且日志语句也不会出现。这就是我添加路线的方式:

@SpringBootApplication
public class CamelApplication extends FatJarRouter {

    public static void main(String ... args) {
        SpringApplication.run(CamelApplication.class, args);
    }

    @Override
    public void configure() throws Exception {
        from("file:input?noop=true")
        .log("Read from the input file")
        .to("file:destination")
        .log("Written to output file");
    }
}

【问题讨论】:

    标签: java spring-boot apache-camel


    【解决方案1】:

    它应该可以工作,而且对我来说确实有效,也许你还没有在你的 IDE 中刷新你的工作区,如果你是这样跟踪进度的话。

    编辑

    我现在知道您的配置有什么问题 - 您的类路径中可能没有 spring-boot-starter-web,因此您的 main 方法不会被阻塞并立即退出。

    您应该从CamelApplication 中删除main 方法并将此条目添加到application.properties

    spring.main.sources = com.example.CamelApplication
    

    或者,您可以将 main 方法更改为运行CamelSpringBootApplicationController

    @SpringBootApplication
    public class CamelApplication extends FatJarRouter {
    
        public static void main(String... args) {
            ApplicationContext applicationContext = SpringApplication.run(DemoApplication.class, args);
            CamelSpringBootApplicationController applicationController =
                    applicationContext.getBean(CamelSpringBootApplicationController.class);
            applicationController.run();
        }
    
        @Override
        public void configure() throws Exception {
            from("file:input?noop=true")
                    .log("Read from the input file")
                    .to("file:destination")
                    .log("Written to output file");
        }
    }
    

    或者,您可以将其添加到您的 pom.xml 以强制嵌入式 Tomcat 启动并阻止您的 main 方法:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    

    【讨论】:

    • 谢谢。我添加了 spring-boot-starter-web 的依赖项,它起作用了。
    【解决方案2】:

    添加到 application.properties 以保持 JVM 运行

    camel.springboot.main-run-controller = true

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多