Reputation: 45
I am trying to poll ftp server for file and process them. I want to do it without xml configuration. I am using spring boot(1.2.5) and spring integration ftp (4.1.5)
I created a bean for session factory
@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;
}
I am trying to configure ftp server polling as follows.
@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);
}
But I am getting following exception when I run the app. Not sure what I am doing wrong. Can somebody help me. (I tried with sftp also with same result)
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
thanks -Ramesh
Upvotes: 1
Views: 1337
Reputation: 121202
The operation:
ftpInboundFileSynchronizer.synchronizeToLocalDirectory(localDirectory);
isn't for your responsibility.
I'm sure you meant exactly this setter:
FtpInboundFileSynchronizingMessageSource.setLocalDirectory(localDirectory);
In other words your @InboundChannelAdapter
should look like this:
@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;
}
Upvotes: 2