使用Spring Integration和JdbcMetadataStore时,Spring Boot无法启动

时间:2018-10-22 17:51:11

标签: spring spring-boot spring-integration spring-integration-sftp

我正在尝试使用Spring Integration通过SFTP读取文件,并使用多个服务器只读取每个文件一次。我已经在Spring Boot中配置了SFTP阅读器,它可以与内存中的元数据存储一起使用。当我使用Postgres配置JdbcMetadataStore时,Spring启动将不再启动,并且除了Tomcat正在关闭之外,没有其他错误消息。我在JPA和Spring WS上使用Spring Boot

2018-10-22 11:16:06.098  INFO 6775 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-10-22 11:16:06.106  INFO 6775 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'metadataStore' has been autodetected for JMX exposure
2018-10-22 11:16:06.114  INFO 6775 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'metadataStore': registering with JMX server as MBean [org.springframework.integration.jdbc.metadata:name=metadataStore,type=JdbcMetadataStore]
2018-10-22 11:16:06.125  INFO 6775 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]

我正在使用基于注释的配置

@Bean
public ConcurrentMetadataStore metadataStore(final DataSource dataSource) {
    return new JdbcMetadataStore(dataSource);
}

@Bean
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
    final DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
    factory.setHost(this.host);
    factory.setPort(this.port);
    factory.setUser(this.username);
    factory.setPassword(this.password);
    factory.setAllowUnknownKeys(true);
    return new CachingSessionFactory<>(factory);
}

@Bean
@InboundChannelAdapter(channel = "stream", poller = @Poller(fixedDelay = "5000"))
public MessageSource<InputStream> sftpMessageSource(ConcurrentMetadataStore metadataStore) {
    final SftpStreamingMessageSource messageSource = new SftpStreamingMessageSource(template(), null);
    messageSource.setRemoteDirectory("/");
     messageSource.setFilter(new SftpPersistentAcceptOnceFileListFilter(metadataStore,
             "INT_"));
    //messageSource.setFilter(new SftpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(),
    //        "streaming"));
    return messageSource;
}

@Bean
@Transformer(inputChannel = "stream", outputChannel = "data")
public org.springframework.integration.transformer.Transformer transformer() {
    return new StreamTransformer();
}

@Bean
public SftpRemoteFileTemplate template() {
    return new SftpRemoteFileTemplate(sftpSessionFactory());
}

1 个答案:

答案 0 :(得分:0)

我注意到在尝试将元数据存储加载到JMX时失败。然后,我在Spring Boot中禁用了JMX,它解决了该问题。不确定为什么无法将bean添加到JMX,但是在spring boot属性(yml)文件中禁用JMX可以解决此问题。

春天:   jmx:     启用:false