Do <int-sftp:inbound-channel-adapter id="sftpInbondAdapte&gt; programatically

时间:2016-02-12 22:06:36

标签: spring-integration

<p>i try to change from xml to programatically configuration one example from spring-boot integration which is <a href=" https:="" github.com="" spring-projects="" spring-integration-samples="" blob="" master="" basic="" sftp="" src="" test="" java="" org="" springframework="" integration="" samples="" sftp="" sftpinboundreceivesample.java"="" rel="nofollow">SftpInboundReceiveSample

These are my configurations :
SftpPoller

DataPackageHandler<TI, TO, T, TD>

FtpConfiguration

@Configuration
public class SftpPoller{

@Autowired
SftpInboundFileSynchronizer sFtpInboundFileSynchronizer;

@Bean
@InboundChannelAdapter(value = "receiveChannel",poller = @Poller(fixedRate = "1000",maxMessagesPerPoll = "1"))
MessageSource<File> pollFtpForFiles() {

    SftpInboundFileSynchronizingMessageSource messageSource = new SftpInboundFileSynchronizingMessageSource(sFtpInboundFileSynchronizer);
    messageSource.setLocalDirectory(new File("local-dir"));
    messageSource.setAutoCreateLocalDirectory(true);

    return messageSource;
}
@Bean
PollableChannel receiveChannel() {return new QueueChannel();}
}

SftpInboundReceiveSample.java

@Configuration
@ImportResource("META-INF/spring/integration/SftpSampleCommon.xml")
@PropertySource("classpath:/application.properties")
public class SftpConfiguration {

    @Autowired
    @Qualifier("serverPort")
    String serverPort;

    @Value("${privateKeyfile}")
    Resource privateKeyfile;
    ...

    @Bean
    DefaultSftpSessionFactory defaultSftpSessionFactory() {
        DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory();
        factory.setHost(host);
        factory.setPrivateKey(privateKeyfile);
        factory.setPrivateKeyPassphrase(passphrase);
        .....
        return factory;
    }

    @Bean
    CachingSessionFactory cachingSessionFactory(DefaultSftpSessionFactory defaultSftpSessionFactory) {
        return new CachingSessionFactory(defaultSftpSessionFactory);
    }

    @Bean
    SftpInboundFileSynchronizer sftpInboundFileSynchronizer(CachingSessionFactory cachingSessionFactory) {
        final SftpInboundFileSynchronizer sftpInboundFileSynchronizer = new SftpInboundFileSynchronizer(cachingSessionFactory);
        sftpInboundFileSynchronizer.setRemoteDirectory("remote-dir");
        sftpInboundFileSynchronizer.setDeleteRemoteFiles(false);
        return sftpInboundFileSynchronizer;
    }
}

Question :

  1. Where can i find @Test public void runDemo() { //load context AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SftpConfiguration.class, SftpPoller.class); .... try{ PollableChannel localFileChannel = context.getBean("receiveChannel", PollableChannel.class); .... // cant find SourcePollingChannelAdapter SourcePollingChannelAdapter adapter = context.getBean(SourcePollingChannelAdapter.class); - adapter.start(); .... } or should I look for different 'PollingChannelAdapter' ?
  2. Is it possible to move all configurations inside xml (except SftpSampleCommon.xml) to POJO? and how ?

thank you for any help and assistance.

1 个答案:

答案 0 :(得分:1)

  1. 您必须在@EnableIntegration上添加@Configuration。这是引导Spring Integration基础架构的主要注释。

  2. 由于SourcePollingChannelAdapter缺席,@EnableIntegration不存在。

  3. 看起来你已经在Java Config中做了所有事情! : - )

  4. 您甚至可以将SftpSampleCommon.xml移动到Java Config。

  5. 请阅读有关Spring Integration Annotation Support的更多信息,并注意Spring Integration Java DSL项目。