我正在使用spring集成的入站通道适配器来递归地从定义的目录中挑选文件,并在从通道接收后处理这些文件。虽然文件名正被保存到元数据文件中但文件不可用于处理渠道。
<int-file:inbound-channel-adapter id="cfpFileIn"
directory="${cfp.flight.data.dir}" auto-startup="true" scanner="csvDirScanner">
<int:poller cron="${cfp.flight.data.dir.polling.delay}" ></int:poller>
</int-file:inbound-channel-adapter>
频道发起人:
@ServiceActivator(inputChannel = "cfpFileIn")
public void run(File file) {
int jobCounter=1;
String fileName = file.getAbsolutePath();
logger.info("Running #################"+fileName );
........
}
csvScanner:
<bean id="csvDirScanner"
class="org.springframework.integration.file.WatchServiceDirectoryScanner">
<constructor-arg index="0" value="${cfp.flight.data.dir}" />
<property name="filter" ref="csvCompositeFilter" />
<property name="autoStartup" value="true" />
</bean>
MetaData:
<bean name="metadataStore"
class="org.springframework.integration.metadata.PropertiesPersistingMetadataStore">
<property name="baseDirectory" value="${metadata.dir}"></property>
</bean>
csvFilter:
<bean id="csvCompositeFilter"
class="org.springframework.integration.file.filters.CompositeFileListFilter">
<constructor-arg>
<list>
<bean
class="org.springframework.integration.file.filters.SimplePatternFileListFilter">
<constructor-arg value="*.csv" />
</bean>
<ref bean="persistentFilter" />
</list>
</constructor-arg>
</bean>
PersistentFilter:
<bean id="persistentFilter"
class="org.springframework.integration.file.filters.FileSystemPersistentAcceptOnceFileListFilter">
<constructor-arg index="0" ref="metadataStore" />
<constructor-arg index="1" name="prefix" value="" />
<property name="flushOnUpdate" value="true" />
</bean>