spring integration sftp错误:Dispatcher没有订阅者

时间:2017-10-17 06:57:13

标签: spring-integration

我正在尝试使用出站网关从sftp服务器下载文件, 我的配置:

@IntegrationComponentScan
@EnableIntegration
@Configuration
public class FtpConfig {

@Bean(name = "myGateway")
@ServiceActivator(inputChannel = "sftpChannel")
public MessageHandler handlerLs() {
    SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sftpSessionFactory(), "mget", "payload");
    sftpOutboundGateway.setLocalDirectory(new File("/Users/xxx/Documents/"));
    return sftpOutboundGateway;

}

@MessagingGateway
public interface OutboundGatewayOption {

    @Gateway(requestChannel = "sftpChannel")
    List<File> mget(String dir);

}

@Bean
public MessageChannel sftpChannel() {
    return new DirectChannel();
    }

}

和执行bean:

@Service
public class DownloadService implements InitializingBean{

@Autowired
FtpConfig.OutboundGatewayOption gatewayOption;

@Override
public void afterPropertiesSet() throws Exception {

   List<File> files =  gatewayOption.mget("/sftp/server/path");
 }
}

我得到了这个例外:org.springframework.messaging.MessageDeliveryException:Dispatcher没有通道'application.sftpChannel'的订阅者。 问题:如何添加“订阅者”?

1 个答案:

答案 0 :(得分:0)

您无法在afterPropertiesSet()中执行消息传递操作符。这太早了:有些豆子可能还没有初始化。而这个例外证实了这个问题。

您必须实施SmartLifecicle,并在start()中执行相同操作。