Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring integration ftp/sftp spring集成-localDirectory不能为null_Spring Integration - Fatal编程技术网

Spring integration ftp/sftp spring集成-localDirectory不能为null

Spring integration ftp/sftp spring集成-localDirectory不能为null,spring-integration,Spring Integration,我正在尝试轮询ftp服务器的文件并处理它们。我想在没有xml配置的情况下完成它。我正在使用SpringBoot(1.2.5)和SpringIntegrationFTP(4.1.5) 我为会话工厂创建了一个bean @Bean public DefaultFtpSessionFactory ftpSessionFactory() { DefaultFtpSessionFactory ftpSessionFactory = new DefaultFtpSessionFactory()

我正在尝试轮询ftp服务器的文件并处理它们。我想在没有xml配置的情况下完成它。我正在使用SpringBoot(1.2.5)和SpringIntegrationFTP(4.1.5)

我为会话工厂创建了一个bean

    @Bean
public DefaultFtpSessionFactory ftpSessionFactory() {
    DefaultFtpSessionFactory ftpSessionFactory = new DefaultFtpSessionFactory();
    ftpSessionFactory.setHost(ftpProperties.ftpHost);
    ftpSessionFactory.setPort(Integer.parseInt(ftpProperties.ftpPort));
    ftpSessionFactory.setUsername(ftpProperties.ftpUser);
    ftpSessionFactory.setPassword(ftpProperties .ftpPassword);
    return ftpSessionFactory;
}
我正在尝试如下配置ftp服务器轮询

    @Bean
@InboundChannelAdapter(value = "receiveChannel", poller = @Poller(fixedRate="1000"))
public MessageSource pollFtpForFiles() {
    File localDirectory = new File(sftpProperties.localDirectory);
    System.err.println("LocalDirectory::"+localDirectory.getAbsolutePath()+"::exists::"+localDirectory.isDirectory());
    FtpInboundFileSynchronizer ftpInboundFileSynchronizer = new FtpInboundFileSynchronizer(ftpSessionFactory());
    ftpInboundFileSynchronizer.setRemoteDirectory(sftpProperties.remoteDirectory);
    ftpInboundFileSynchronizer.synchronizeToLocalDirectory(localDirectory);
    return new FtpInboundFileSynchronizingMessageSource(ftpInboundFileSynchronizer);
}
但当我运行应用程序时,我遇到了以下异常。 不知道我做错了什么。谁能帮帮我吗。(我用sftp试过,结果也一样)

LocalDirectory::localDirForSftpTransfer::exists::true

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sftpInboundSetup' defined in file [/Users/rsamban/Documents/workspace/Second/target/classes/com/yesVin/integration/sftp/SftpInboundSetup.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pollFtpForFiles' defined in class path resource [com/yesVin/integration/sftp/SftpInboundSetup.class]: **Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: localDirectory must not be null**
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
    at com.yesVin.integration.SecondApplication.main(SecondApplication.java:16)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pollFtpForFiles' defined in class path resource [com/yesVin/integration/sftp/SftpInboundSetup.class]: **Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: localDirectory must not be null**
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.integration.config.annotation.AbstractMethodAnnotationPostProcessor.resolveTargetBeanFromMethodWithBeanAnnotation(AbstractMethodAnnotationPostProcessor.java:362)
    at org.springframework.integration.config.annotation.InboundChannelAdapterAnnotationPostProcessor.createMessageSource(InboundChannelAdapterAnnotationPostProcessor.java:76)
    at org.springframework.integration.config.annotation.InboundChannelAdapterAnnotationPostProcessor.postProcess(InboundChannelAdapterAnnotationPostProcessor.java:62)
    at org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor$1.doWith(MessagingAnnotationPostProcessor.java:151)
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:495)
    at org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor.postProcessAfterInitialization(MessagingAnnotationPostProcessor.java:131)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    ... 13 more
**Caused by: java.lang.IllegalArgumentException: localDirectory must not be null**
    at org.springframework.util.Assert.notNull(Assert.java:112)
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource.afterPropertiesSet(AbstractInboundFileSynchronizingMessageSource.java:132)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
    ... 28 more
谢谢 -Ramesh操作:

ftpInboundFileSynchronizer.synchronizeToLocalDirectory(localDirectory);
这不是你的责任

我相信你的意思就是这个塞特:

FtpInboundFileSynchronizingMessageSource.setLocalDirectory(localDirectory);
换句话说,您的
@InboundChannelAdapter
应该如下所示:

@Bean
@InboundChannelAdapter(value = "receiveChannel", poller = @Poller(fixedRate="1000"))
public MessageSource pollFtpForFiles() {
    File localDirectory = new File(sftpProperties.localDirectory);
     System.err.println("LocalDirectory::"+localDirectory.getAbsolutePath()+"::exists::"+localDirectory.isDirectory());
    FtpInboundFileSynchronizer ftpInboundFileSynchronizer = new FtpInboundFileSynchronizer(ftpSessionFactory());
    ftpInboundFileSynchronizer.setRemoteDirectory(sftpProperties.remoteDirectory);
    FtpInboundFileSynchronizingMessageSource messageSource = new FtpInboundFileSynchronizingMessageSource(ftpInboundFileSynchronizer);
    messageSource.setLocalDirectory(localDirectory);
    return messageSource;
}