2014-10-20 26 views
1

我有一个工作应用程序,它从属性文件中指定的目录中读取并写入其他目录。以下是用于读取和写入的入站和出站通道适配器。更改出站通道适配器上的目录

<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" /> 

我有一个需要允许在应用程序运行时更改目录。我创建了让我用下面的代码停止轮询服务和改变输入目录控制总线:

SourcePollingChannelAdapter adapter = context.getBean("inputFileChannelAdapter", SourcePollingChannelAdapter.class); 
    FileReadingMessageSource source = context.getBean("inputFileChannelAdapter.source", FileReadingMessageSource.class); 
    File monitorFileDir = new File("C:\newInput"); 
    source.setDirectory(monitorFileDir); 

不过,我不知道如何来完成相同的出站通道适配器。我试图得到参考了约束channnel适配器,然后创建一个新的EventDivenConsumer和FileWritingMessageHandler和重新分配的参考,但它没有工作,我觉得我标题下与解决方案在错误的道路。任何建议,将不胜感激。

回答

0

对于FileReadingMessageSource你是否正确。

对于FileWritingMessageHandler你不能那样做,因为directory转换为private final Expression destinationDirectoryExpression;

所以,这是一个提示,我们如何能够克服自己的change dir a runtime用例:

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

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

有,你总是可以在运行时从ApplicationContext retrive这个bean并更改值目标目录:

AtomicReference<String> targetDir = (AtomicReference<String>) context.getBean("targetDir", AtomicReference.class); 
targetDir.set("/new/target/dir"); 
+0

非常感谢阿尔乔姆,即工作!我很欣赏所有的细节。 – golfnguitarz 2014-10-20 17:39:16

+0

我不得不使用远程目录的表情,目录表达不承认(我的版本的春天?) 伟大的作品,否则 – BenoitParis 2015-07-16 10:28:52

+0

'远程目录expression'?因此,对于SFTP使用''或类似命令。 – 2015-07-16 12:26:06

0

,如果你想它的基础上的信息,您可以使用directory-expression="@someBean.whereTo()""@someBean.whereTo(#root)"

使用较新版本的框架,您可以获得对bean名称为finishedDataFiles.handler的处理程序的引用,但正如@Artem所说,目录是final

相关问题