Spring integration 更改文件上的动态目录:入站通道适配器
我是Spring的新手,正在使用。 我将尝试动态更改Spring integration 更改文件上的动态目录:入站通道适配器,spring-integration,citrus-framework,Spring Integration,Citrus Framework,我是Spring的新手,正在使用。 我将尝试动态更改入站通道适配器目的地变量。此变量位于属性文件中,并随时更改 目前我正在使用一个AtomicReference,我在java代码中更改了它的值 在context.xml中: <bean id="targetDir" class="java.util.concurrent.atomic.AtomicReference"> <constructor-arg value="${output.path.temp}
入站通道适配器目的地变量。此变量位于属性文件中,并随时更改
目前我正在使用一个AtomicReference
,我在java代码中更改了它的值
在context.xml
中:
<bean id="targetDir" class="java.util.concurrent.atomic.AtomicReference">
<constructor-arg value="${output.path.temp}"/>
</bean>
<file:inbound-channel-adapter id="fileInboundAdapter" auto-create-directory="false"
channel="fileChannel" directory="file:@targetDir.get()" auto-startup="false"
filename-pattern="*.xml">
<si:poller cron="0 * * * * ?"/>
</file:inbound-channel-adapter>
在java文件中:
SourcePollingChannelAdapter fileInboundAdapter = (SourcePollingChannelAdapter)context.getApplicationContext().getBean("fileInboundAdapter");
if (fileInboundAdapter.isRunning()) {
fileInboundAdapter.stop();
@SuppressWarnings("unchecked")
AtomicReference<String> targetDir = (AtomicReference<String>)
context.getApplicationContext().getBean("targetDir", AtomicReference.class);
targetDir.set(strOutPath[0]+"/"+strOutPath[1]+"/"+strOutPath[2]+"/"+strOutPath[3]+"/");
fileInboundAdapter.start();
}
SourcePollingChannelAdapter fileInboundAdapter=(SourcePollingChannelAdapter)context.getApplicationContext().getBean(“fileInboundAdapter”);
if(fileInboundAdapter.isRunning()){
fileInboundAdapter.stop();
@抑制警告(“未选中”)
AtomicReference targetDir=(AtomicReference)
getBean(“targetDir”,AtomicReference.class);
targetDir.set(strOutPath[0]+“/”+strOutPath[1]+“/”+strOutPath[2]+“/”+strOutPath[3]+“/”);
fileInboundAdapter.start();
}
此解决方案不起作用。。。有人有什么解决办法吗
非常感谢。没错。因为您的原子引用
对目标目录
没有影响
您可以这样做directory=“file:@targetDir.get()”
。这根本不正确,因为此字符串将尝试转换为文件
对象。如果要在此处使用SpEL,应如下所示:
directory="#{targetDir.get()}"
SourcePollingChannelAdapter fileInboundAdapter = (SourcePollingChannelAdapter)context.getApplicationContext().getBean("fileInboundAdapter");
if (fileInboundAdapter.isRunning())
fileInboundAdapter.stop();
FileReadingMessageSource source = (FileReadingMessageSource) context.getApplicationContext().getBean("fileInboundAdapter.source");
source.setDirectory(new File(strOutPath[0]+"/"+strOutPath[1]+"/"+strOutPath[2]+"/"+strOutPath[3]+"/"));
fileInboundAdapter.start();
}
没有任何文件:
前缀
无论如何,它没有帮助,因为SpEL在applicationContext strtup上只计算一次
由于您要在运行时更改目录
,因此您应该从您的服务中使用FileReadingMessageSource.setDirectory
。大概是这样的:
directory="#{targetDir.get()}"
SourcePollingChannelAdapter fileInboundAdapter = (SourcePollingChannelAdapter)context.getApplicationContext().getBean("fileInboundAdapter");
if (fileInboundAdapter.isRunning())
fileInboundAdapter.stop();
FileReadingMessageSource source = (FileReadingMessageSource) context.getApplicationContext().getBean("fileInboundAdapter.source");
source.setDirectory(new File(strOutPath[0]+"/"+strOutPath[1]+"/"+strOutPath[2]+"/"+strOutPath[3]+"/"));
fileInboundAdapter.start();
}
然后去掉原子参考
从一开始,您就可以直接为目录
属性使用属性占位符