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