【问题标题】:Spring Integration SftpOutboundChannelAdapter - how to pass in ftp parameters at runtimeSpring Integration SftpOutboundChannelAdapter - 如何在运行时传入ftp参数
【发布时间】:2016-12-04 19:52:28
【问题描述】:

我需要使用 Spring 集成的 sftp 适配器构建一个独立的 api,但是调用者将传入 sftp 连接参数(主机、用户、pwd 等),因此我无法在 spring 上下文 xml 中初始化它们。我正在寻找有关无需在每次调用时拆卸和重新创建应用程序上下文的最佳方法的建议。这是我现在的上下文 xml,我想将 DefaultSftpSessionFactory 参数外部化。

<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'"      />       

【问题讨论】:

    标签: spring-integration sftp spring-integration-sftp


    【解决方案1】:

    请参阅dynamic ftp sample app

    它使用动态路由器为每个新目的地创建一个新的迷你(参数化)应用程序上下文,并缓存它们以供重复使用。

    这很简单;示例使用 XML;如果您更喜欢 Java 配置,this answerits follow-up 对入站邮件适配器使用类似的技术。

    如果您出于某种原因不想使用此技术,另一种选择是将DelegatingSessionFactory 与自定义SessionFactoryLocator 一起使用,它会即时创建会话工厂。

    【讨论】:

    • 另见spring.io/blog/2016/07/08/…。现在您可以在运行时配置整个流程。就像您想要的 FTP 一样
    • Gary - 有没有 DelegatingSessionFactory 和 SessionFactoryLocator 的例子?
    • 我不知道,但将主机/端口/凭据添加到消息头并在工厂定位器中使用它们应该不难。这周我在SpringOne平台大会上;如果您在此处添加评论提醒我,我可以在下周创建一个示例。
    猜你喜欢
    • 1970-01-01
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    • 1970-01-01
    • 2020-03-26
    • 1970-01-01
    相关资源
    最近更新 更多