我需要使用 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'" />