Java ApacheCamel在目录之间复制文件

Java ApacheCamel在目录之间复制文件,java,spring-boot,apache-camel,Java,Spring Boot,Apache Camel,我对apache camel和spring boot还不熟悉。我正在编写一个应用程序,需要将文件从文件夹传输到jms队列。但在此之前,我试图将文件从一个文件夹传输到另一个文件夹,但这并没有发生。将应用程序作为spring启动应用程序运行时,将创建输入文件夹。如果将文件粘贴到此文件夹中,则不会形成目标文件夹,也不会显示日志语句。以下是我添加路线的方式: @SpringBootApplication public class CamelApplication extends FatJarRouter

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

@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");
    }
}

它应该可以工作,对我来说也可以,也许您还没有在IDE中刷新您的工作区,如果这是您跟踪进度的方式的话

编辑

我现在明白了您的配置有什么问题了——您的类路径上可能没有spring boot starter web,所以您的主方法不会被阻止并立即退出

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

spring.main.sources = com.example.CamelApplication
或者,您可以将主方法更改为运行
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启动并阻止您的主方法:

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

org.springframework.boot
SpringBootStarterWeb

它应该可以工作,对我来说也可以,也许您还没有在IDE中刷新您的工作区,如果这是您跟踪进度的方式的话

编辑

我现在明白了您的配置有什么问题了——您的类路径上可能没有spring boot starter web,所以您的主方法不会被阻止并立即退出

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

spring.main.sources = com.example.CamelApplication
或者,您可以将主方法更改为运行
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启动并阻止您的主方法:

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

org.springframework.boot
SpringBootStarterWeb

谢谢。我为spring boot starter web添加了依赖项,它成功了。谢谢。我为SpringBootStarterWeb添加了依赖项,它成功了。