FTP 工作階段工廠

Spring Integration 提供了可用於建立 FTP (或 FTPS) 工作階段的工廠。

預設工廠

從 3.0 版開始,工作階段預設不再快取。請參閱 FTP 工作階段快取

在設定 FTP 适配器之前,您必須設定 FTP 工作階段工廠。您可以使用常規 Bean 定義來設定 FTP 工作階段工廠,其中實作類別為 o.s.i.ftp.session.DefaultFtpSessionFactory。以下範例顯示基本設定

<bean id="ftpClientFactory"
    class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
    <property name="host" value="localhost"/>
    <property name="port" value="22"/>
    <property name="username" value="kermit"/>
    <property name="password" value="frog"/>
    <property name="clientMode" value="0"/>
    <property name="fileType" value="2"/>
    <property name="bufferSize" value="100000"/>
</bean>

對於 FTPS 連線,您可以改用 o.s.i.ftp.session.DefaultFtpsSessionFactory

以下範例顯示完整設定

<bean id="ftpClientFactory"
    class="org.springframework.integration.ftp.session.DefaultFtpsSessionFactory">
    <property name="host" value="localhost"/>
    <property name="port" value="22"/>
    <property name="username" value="oleg"/>
    <property name="password" value="password"/>
    <property name="clientMode" value="1"/>
    <property name="fileType" value="2"/>
    <property name="useClientMode" value="true"/>
    <property name="cipherSuites" value="a,b.c"/>
    <property name="keyManager" ref="keyManager"/>
    <property name="protocol" value="SSL"/>
    <property name="trustManager" ref="trustManager"/>
    <property name="prot" value="P"/>
    <property name="needClientAuth" value="true"/>
    <property name="authValue" value="oleg"/>
    <property name="sessionCreation" value="true"/>
    <property name="protocols" value="SSL, TLS"/>
    <property name="implicit" value="true"/>
</bean>
如果您遇到連線問題,並希望追蹤工作階段建立以及查看輪詢了哪些工作階段,您可以將記錄器設定為 TRACE 層級來啟用工作階段追蹤 (例如,log4j.category.org.springframework.integration.file=TRACE)。

現在您只需要將這些工作階段工廠注入到您的适配器中。适配器使用的協定 (FTP 或 FTPS) 取決於已注入到适配器中的工作階段工廠類型。

為 FTP 或 FTPS 工作階段工廠提供值的更實用方法是使用 Spring 的屬性佔位符支援 (請參閱 docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-factory-placeholderconfigurer)。