title: Spring Integration SFTP Example with Spring Boot
body: <p>We are using the latest Spring Boot for a Spring app and using the latest Spring Integration for SFTP.   I've been to the Spring Integration SFTP documentation site, and I took the Spring Boot Configuration as is:</p>
  
  <pre><code> @Bean
  public SessionFactory&lt;LsEntry&gt; sftpSessionFactory() {
      DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
      factory.setHost("localhost");
      factory.setPort(port);
      factory.setUser("foo");
      factory.setPassword("foo");
      factory.setAllowUnknownKeys(true);
      return new CachingSessionFactory&lt;LsEntry&gt;(factory);
  }
  
  @Bean
  public SftpInboundFileSynchronizer sftpInboundFileSynchronizer() {
      SftpInboundFileSynchronizer fileSynchronizer = new SftpInboundFileSynchronizer(sftpSessionFactory());
      fileSynchronizer.setDeleteRemoteFiles(false);
      fileSynchronizer.setRemoteDirectory("/");
      fileSynchronizer.setFilter(new SftpSimplePatternFileListFilter("*.xml"));
      return fileSynchronizer;
  }
  
  @Bean
  @InboundChannelAdapter(channel = "sftpChannel")
  public MessageSource&lt;File&gt; sftpMessageSource() {
      SftpInboundFileSynchronizingMessageSource source =
              new SftpInboundFileSynchronizingMessageSource(sftpInboundFileSynchronizer());
      source.setLocalDirectory(new File("ftp-inbound"));
      source.setAutoCreateLocalDirectory(true);
      source.setLocalFilter(new AcceptOnceFileListFilter&lt;File&gt;());
      return source;
  }
  
  @Bean
  @ServiceActivator(inputChannel = "sftpChannel")
  public MessageHandler handler() {
      return new MessageHandler() {
  
          @Override
          public void handleMessage(Message&lt;?&gt; message) throws MessagingException {
              System.out.println(message.getPayload());
          }
  
      };
  }
  </code></pre>
  
  <p>Let me be clear, after cutting and pasting, there are some unit tests that run.  However, when loading the application context there was an error message because the Polling wasn't there.   </p>
  
  <p>When I googled that error, other posts on StackOverflow said I also had to add to remove this error message when loading the application context.</p>
  
  <pre><code>@Bean(name = PollerMetadata.DEFAULT_POLLER)
  public PollerMetadata defaultPoller() {
  
      PollerMetadata pollerMetadata = new PollerMetadata();
      pollerMetadata.setTrigger(new PeriodicTrigger(60));
      return pollerMetadata;
  }
  </code></pre>
  
  <p>When I added this code, THEN at least my build would work and the tests would run because the application context was now being loaded correctly.</p>
  
  <p>Now I am looking for a code sample on how to make this work and move files?   The Spring Integration SFTP examples on GitHub are ok, but not great ... far from it.</p>
  
  <p>The Basic Spring Integration Example shows how to read files from an SFTP Server, if the data is configured with an application-context.xml file.   Where is the example where a Spring Boot configuration is used, and then the code to read from that server, and the code for the test?</p>
  
  <p>I understand that regardless of whether you use a Java class for Spring Boot configuration or an application-context.xml file ... the working code should work the same for autowired SFTP channels and some inbound channel adapter.</p>
  
  <p>So here is the code, I am trying to make work:</p>
  
  <pre><code>@Component
  @Profile("sftpInputFetch")
  public class SFTPInputFetcher implements InputFetcher
  {
      // The PollableChannel seems fine
      @Autowired
      PollableChannel sftpChannel;
  
      @Autowired
      SourcePollingChannelAdapter sftpChannelAdapter;
  
  @Override
  public Stream&lt;String&gt; fetchLatest() throws FileNotFoundException
  {
      Stream&lt;String&gt; stream = null;
      sftpChannelAdapter.start();
      Message&lt;?&gt; received = sftpChannel.receive();
      File file = (File)received.getPayload();
      // get Stream&lt;String&gt; from file
      return stream;
  }
  </code></pre>
  
  <p>Currently, "sftpChannelAdapter.start();" is the part I am having trouble with.
  This implementation does not find the "SourcePollingChannelAdapter" class.  </p>
  
  <p>If this was defined in the classic XML application context with an "id" then this code autowires just fine.  With a Spring Boot configuration, it doesn't look like you can define an "id" for a bean.  </p>
  
  <p>This just stems from my lack of knowledge on how to convert from using a traditional application-context XML file WITH annotations in the code, to using a complete Spring Boot application context configuration file.</p>
  
  <p>Any help with this is much appreciated.    Thanks!</p>