2016-07-30 24 views
1

我需要使用Spring集成的sftp適配器構建獨立API,但調用者將傳遞sftp連接參數(host,user,pwd等)和所以我不能在spring上下文xml中初始化它們。我正在尋找最佳方式的建議,以避免需要在每次調用時拆卸和重新創建應用程序上下文。這裏是我的上下文xml現在,我想將外部參數DefaultSftpSessionFactory。Spring集成SftpOutboundChannelAdapter - 如何在運行時傳遞ftp參數

<bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory"> 
    <property name="host" value="${host}" /> 
    <property name="port" value="${serverport}" /> 
    <property name="user" value="${username}" /> 
    <property name="password" value="${password}" /> 
    <property name="allowUnknownKeys" value="true" /> 
</bean> 
<int:channel id="inputChannel" /> 
<int-sftp:outbound-channel-adapter id="sftpOutboundAdapter" 
    session-factory="sftpSessionFactory" 
    channel="inputChannel" 
    charset="UTF-8" 
    remote-file-separator="/" 
    remote-directory="/accounts/12026622/Reports/" 
    use-temporary-file-name="false" 
    mode="REPLACE" 
    remote-filename-generator-expression="payload.getName() + '-foo'"  />  

回答

0

查看dynamic ftp sample app

它使用動態路由器爲每個新目標創建一個新的迷你(參數化)應用程序上下文並緩存它們以供重用。

這很簡單;該示例使用XML;如果您更喜歡Java配置,則this answerits follow-up對入站郵件適配器使用相似的技術。

如果你不想使用這種技術出於某種原因,另一種選擇是使用DelegatingSessionFactory和定製的SessionFactoryLocator,它可以即時創建會話工廠。

+0

另請參閱https://spring.io/blog/2016/07/08/java-dsl-for-spring-integration-1-2-m1-and-1-1-3-are-available。現在,您可以在運行時配置整個流程。就像你想要的FTP –

+0

Gary - 是否有一個DelegatingSessionFactory與SessionFactoryLocator的例子? – javakart

+0

不是我知道的,但將主機/端口/憑證添加到消息標題並在工廠定位器中使用它們應該不困難。我在本週參加SpringOne平臺大會;我可以在下週創建一個例子,如果您在此處添加評論時提醒我。 –

相關問題