如何在Spring Integration中使用通道但仅使用java config

时间:2017-02-28 13:18:37

标签: java spring spring-integration spring-batch spring-integration-sftp

我一直在网上阅读Spring文档和论坛。我做了类似的事情:sftp with java config in spring

  

关键是我想使用频道发送消息,所以   我已经创建了一个像这样的方法

private void MethodToSendMessageUsingSftp(MessageChannel channel, File file){
        final Message<File> message = MessageBuilder.withPayload(file).build();
        channel.send(message);
}

但我不知道如何获取频道以将其设置为MethodToSendMessageUsingSftp方法,并发送消息。

顺便说一句,我正在做所有这些事情只是因为我在项目中将一些东西从xml改为java config:

所以,我的旧项目看起来像这样:

<bean id="uploadToSftpTasklet" class="someClass" scope="step">
    <property name="sftpChannel" ref="sftpChannel"/>
</bean>

<int:channel id="sftpChannel"/>

<int-sftp:outbound-channel-adapter id="sftpOutboundAdapter"
                                   channel="sftpChannel"
                                   session-factory="sftpSessionFactory"
                                   remote-directory-expression="whatever"
                                   charset="UTF-8"
                                   auto-create-directory="true"
                                   use-temporary-file-name="false"
</int-sftp:outbound-channel-adapter>

如果你看到我的uploadToSftpTasklet我引用了sftpChannel,那就是我想用java配置做的事情。

1 个答案:

答案 0 :(得分:0)

让我猜一下:该方法是应用程序托管bean中某些服务的一部分。因此,您可以@Autowired进入此服务,并使用逻辑。

虽然,老实说,你的问题并不清楚。 Spring Integration中的所有内容都是一个bean,完全基于Spring Framework。因此,依赖注入规则和所有配置技巧也适用于此处。