首页 > 解决方案 > 如何在配置为xml配置的spring-integration项目中使用@RefreshScrop

问题描述

我正在使用 spring 集成将 ftp 文件传输到远程服务器,并且我正在使用基于 xml 的配置。我想使用 spring cloud config ,所以我可以将所有属性文件移动到 git 并使用 @RefreshScope 刷新属性。在只有 xml 的 spring 集成中实现这一目标的最佳方法是什么。

我有以下代码:

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

标签: spring-integration

解决方案


尝试scope="refresh"<aop:scoped-proxy/>为该 bean 定义。像这样的东西:

<bean id="inDefaultSftpSessionFactory"
    class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory"
    scope="refresh">
    <property name="host" value="${sftp.host}" />
    <property name="port" value="${sftp.port}" />
    <property name="user" value="${sftp.username}" />
    <property name="password" value="${sftp.password}" />
    <property name="allowUnknownKeys" value="true" />
    <aop:scoped-proxy/>
</bean>

推荐阅读