Spring integration 更改出站通道适配器上的目录

Spring integration 更改出站通道适配器上的目录,spring-integration,Spring Integration,我有一个正在工作的应用程序,它从属性文件中指定的目录中读取数据,然后写入另一个目录。以下是用于读写的入站和出站通道适配器 <file:inbound-channel-adapter id="inputFileChannelAdapter" channel="fileIn" directory="${dir.monitor}" auto-startup="false" prevent-duplicates="false" filename-pattern="*.done" &g

我有一个正在工作的应用程序,它从属性文件中指定的目录中读取数据,然后写入另一个目录。以下是用于读写的入站和出站通道适配器

<file:inbound-channel-adapter id="inputFileChannelAdapter" channel="fileIn"    directory="${dir.monitor}"
    auto-startup="false" prevent-duplicates="false" filename-pattern="*.done" >
    <int:poller id="inputFilePoller" time-unit="SECONDS" fixed-delay="1" max-messages-per-poll="100" />
</file:inbound-channel-adapter>


<int:channel id="finishedFileChannel"/>
<file:outbound-channel-adapter id="finishedDataFiles" delete-source-files="true" auto-create-directory="false" 
    directory="${dir.finished}" channel="finishedFileChannel" />
但是,我不知道如何为出站通道适配器实现同样的功能。我尝试获取对外部通道适配器的引用,然后创建一个新的EventDivenConsumer和FileWritingMessageHandler,并将其重新分配给引用,但没有成功,我觉得我使用该解决方案走错了方向。如有任何建议,我们将不胜感激。

如果您希望基于消息使用目录表达式=@someBean.whereTo或@someBean.whereToroot

对于较新版本的框架,您可以使用bean名finishedatafiles.handler获得对处理程序的引用,但是,正如@Artem所说,目录是最终的。

对于FileReadingMessageSource,您可以这样做

对于FileWritingMessageHandler,您不能这样做,因为目录已转换为私有最终表达式destinationDirectoryExpression

因此,这是我们如何克服运行时用例中的更改的技巧:

<bean id="targetDir" class="java.util.concurrent.atomic.AtomicReference">
    <constructor-arg value="${dir.finished}"/>
</bean>

<file:outbound-channel-adapter directory-expression="@targetDir.get()"/>

非常感谢阿泰姆,这成功了!我很感激所有的细节。我必须使用远程目录表达式,因为我的spring版本无法识别目录表达式?很好用的远程目录表达式?因此,您正在使用或类似于SFTP。
<bean id="targetDir" class="java.util.concurrent.atomic.AtomicReference">
    <constructor-arg value="${dir.finished}"/>
</bean>

<file:outbound-channel-adapter directory-expression="@targetDir.get()"/>
AtomicReference<String> targetDir = (AtomicReference<String>) context.getBean("targetDir", AtomicReference.class);
targetDir.set("/new/target/dir");