0

我一直在阅读 Internet 上的 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 config 做的事情。

4

1 回答 1

0

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

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

于 2017-02-28T13:26:14.063 回答