Spring integration 如何获取privateKey作为org.springframework.core.io.Resource

Spring integration 如何获取privateKey作为org.springframework.core.io.Resource,spring-integration,Spring Integration,我正在使用spring集成使用私钥连接到SFTP服务器。 私钥作为外部字符串进入应用程序。如何在以下代码中使用密钥: <bean id="test" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory"> <property name="host" value="${host}" /> <property name

我正在使用spring集成使用私钥连接到SFTP服务器。 私钥作为外部字符串进入应用程序。如何在以下代码中使用密钥:

 <bean id="test"
        class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
        <property name="host" value="${host}" />
        <property name="privateKey" value="" />
        <property name="port" value="${port}" />
        <property name="user" value="${username}" />
        <property name="allowUnknownKeys" value="true" />
    </bean>

如果你的意思是你的密钥被编码成某个字符串,那么你需要考虑把它封装到BytErayRealth.T/P> 假设您将其作为某个文件中的属性,并使用属性占位符:

<bean id="test"
    class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
    <property name="host" value="${host}" />
    <property name="privateKey">
        <bean class="org.springframework.core.io.ByteArrayResource">
              <constructor-arg value="#{'${my.sftp.private.key}'.bytes}"/>
        </bean>
    </property>
    <property name="port" value="${port}" />
    <property name="user" value="${username}" />
    <property name="allowUnknownKeys" value="true" />
</bean>