Java 是否有方法通过代码启动文件:入站通道适配器?
我遇到这样一种情况:一个特定的文件要从一个位置复制到另一个位置。不需要轮询,因为操作将被故意触发。此外,从中提取文件的目录也在运行时确定 我可以有如下配置:Java 是否有方法通过代码启动文件:入站通道适配器?,java,spring-integration,Java,Spring Integration,我遇到这样一种情况:一个特定的文件要从一个位置复制到另一个位置。不需要轮询,因为操作将被故意触发。此外,从中提取文件的目录也在运行时确定 我可以有如下配置: <int-file:inbound-channel-adapter id="filesIn" directory="@outPathBean.getPath()" channel="abc" filter="compositeFilter" > <int:poller id="poller" fixed-delay
<int-file:inbound-channel-adapter id="filesIn" directory="@outPathBean.getPath()" channel="abc" filter="compositeFilter" >
<int:poller id="poller" fixed-delay="5000" />
</int-file:inbound-channel-adapter>
<int:channel id="abc"/>
<int-file:outbound-channel-adapter channel="abc" id="filesOut"
directory-expression="file:${paths.root}"
delete-source-files="true" filename-generator="fileNameGenerator" />
还配置了filenamegenerator和复合过滤器类
我是春天的新手。请给我指出正确的方向 如中所述,您可以使用
FireOnCatrigger
,并根据需要启动/停止适配器
要获取对适配器的引用(aSourcePollingChannelAdapter
),请将其作为生命周期bean(start()
/stop()
等)注入(或@Autowire
等)
或者,您可以使用FileReadingMessageSource
以编程方式完成整个过程,如中所述。启动/停止适配器示例。如果有用的话
SourcePollingChannelAdapter sourcePollingChannelAdapter = (SourcePollingChannelAdapter) context
.getBean("filesIn"); //adapter id in the bean configuration
// Stop
if (sourcePollingChannelAdapter.isRunning()) {
sourcePollingChannelAdapter.stop();
}
// Set Cron Expression if required when start or use any triggers
CronTrigger cronTrigger = new CronTrigger("* * * * * ?");
sourcePollingChannelAdapter.setTrigger(cronTrigger);
// Start
if (!sourcePollingChannelAdapter.isRunning()) {
sourcePollingChannelAdapter.start();
}
将尝试此参考答案了解更多详细信息??我是spring Integration的新手。您到底在挣扎什么?这些答案涉及到一些细节。以下是我从第一个选项中了解到的:1。将my xml中的轮询器标记更改为:。2.添加一个bean 3。公共静态类FireOnMetrigger实现触发器{boolean done;public Date nextExecutionTime(TriggerContext TriggerContext){if(done){return null;}done=true;return new Date();}public void reset(){done=false;}}4。我可以使用@Autowire,但不知道如何将其作为生命周期bean使用。??只需@Autowire
aSourcePollingChannnelAdapter
或Lifecycle
,使用适配器的id调用start()
。