簡體   English   中英

如何在Spring Integration中使用通道但僅使用Java配置

[英]How to use the channel in Spring Integration but Using just java config

我一直在閱讀Spring文檔和Internet上的論壇。 我做了一些非常類似的事情: 在春季使用Java配置進行sftp

關鍵是我想使用該通道發送消息,所以我創建了一個像這樣的方法

 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進行的操作。

讓我猜測:該方法是應用程序中的某些服務(托管Bean)的一部分。 因此,您可以@Autowired將該通道連接到此服務中,並@Autowired邏輯。

雖然,老實說,您的問題尚不清楚。 Spring Integration中的所有內容都是一個bean,並且完全基於Spring Framework。 因此,這里也應用了依賴項注入規則和所有配置技巧。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM