调度程序没有传出 sftp 通道的订阅者

Dispatcher has no subscribers for outgoing sftp channel

我正在使用 spring-integration-sftp,我的目标是将本地文件推送到 SFTP(目前仅此而已,无需确认或其他任何内容)。我的配置如下:

@EnableIntegration
@IntegrationComponentScan
@Configuration
@Lazy
public class SftpConfiguration {

    @Bean(name = "toSftpChannel")
    public MessageChannel sftpMessageChannel() {
        return new DirectChannel();
    }

    @Bean
    public DefaultSftpSessionFactory sftpSessionFactory(
            @Qualifier("sftpDestination") SftpPropertiesService sftpPropertiesService 
    ) {
        DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory();
        factory.setHost(sftpPropertiesService.getServiceHost());
        factory.setPort(22);
        factory.setUser(sftpPropertiesService.getUsername());
        factory.setPassword(sftpPropertiesService.getPassword());
        factory.setAllowUnknownKeys(true);
        return factory;
    }

    @Bean
    public SftpRemoteFileTemplate sftpRemoteFileTemplate(DefaultSftpSessionFactory dssf,
            @Value("${sftp.output.directory}") String outputDirectory) {
        SftpRemoteFileTemplate template = new SftpRemoteFileTemplate(dssf);
        template.setRemoteDirectoryExpression(new LiteralExpression(outputDirectory));
        return template;
    }

    @Bean
    @ServiceActivator(inputChannel = "toSftpChannel")
    public MessageHandler handler(SftpRemoteFileTemplate sftpRemoteFileTemplate) {
        SftpOutboundGateway gateway =
            new SftpOutboundGateway(sftpRemoteFileTemplate, Command.PUT.getCommand(), "payload");
        gateway.setFileExistsMode(FileExistsMode.FAIL);
        return gateway;
    }

    @MessagingGateway
    public interface OutputSftpGateway {
        @Gateway(requestChannel = "toSftpChannel")
        void sendToSftp(File file);
    }
}

而发送只是

private final OutputSftpGateway outputSftpGateway;
...
outputSftpGateway.sendToSftp(file);

当我运行我的代码时,我首先得到

A bean definition with name 'toSftpChannel' exists, but failed to be created; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'toSftpChannel': Requested bean is currently in creation: Is there an unresolvable circular reference?

这在惰性初始化中是一种预期(尽管仍然需要修复它),但在第二次和随后的运行中我遇到了问题

Exception occurred during request processing. org.springframework.messaging.MessageDeliveryException. Dispatcher has no subscribers for channel 'application.toSftpChannel'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers

老实说,我是 Spring 消息传递魔术的新手,所以原因可能非常愚蠢,但有人可以提示我为什么会发生这种情况,我该如何解决?

@Lazy 可能对那些 bean 初始化有一些影响。考虑划分您的配置逻辑以仅提取那些不能与 @Lazy 一起使用的 beans。并且不要将其应用于那些 Spring 集成组件。