Spring Integration-File Adapter使用

阅读更多

File Adapter主要应用于企业应用程序之间共享文件系统的情况,一个应用写入,而其他应用通过轮询文件系统进行读取。File Adapter从不同的文件系统提取文件再转变成框架的Message并发布至通道中,或者从通道中提取Message再转变为文件并写入文件系统中。

 

一、配置环境

1.下载Spring Integration

http://s3.amazonaws.com/dist.springframework.org/release/INT/spring-integration-2.1.0.RELEASE-dist.zip

 

2.配置classpath依赖的jar

 

spring-integration-core-2.1.0.RELEASE.jar 

spring-integration-file-2.1.0.RELEASE.jar

org.springframework.asm-3.1.0.RELEASE.jar

org.springframework.aop-3.1.0.RELEASE.jar

org.springframework.beans-3.1.0.RELEASE.jar

org.springframework.core-3.1.0.RELEASE.jar

org.springframework.context-3.1.0.RELEASE.jar

org.springframework.context.support-3.1.0.RELEASE.jar

org.springframework.expression-3.1.0.RELEASE.jar

aopalliance-1.0.jar

commons-logging-1.1.1.jar

 

二、XML配置文件:spring-integration-file-context.xml

 


	
	
	
	
	
	    
	
	
	
	

 

三、编写测试类

 

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestFileSupport {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext(
		"spring-integration-file-context.xml");
	}
}

 

四、示例说明

实现功能:每秒间隔轮询D:/spring-integration-samples/input目录,如果发现该目录有文件,就依次复制到D:/spring-integration-samples/output目录中。实际上就是文件copy的功能

该示例使用了Spring Integration提供的File适配器。

 

深入File Adapter

1.防止重复读取:prevent-duplicates="true"

 

 

2.文件过滤:filename-pattern="*.doc"或者filename-regex="[ABC]_positions.doc"


或者

 

 

3.文件锁:


    
    ……

 

4.删除源文件:delete-source-files="true"

 

 

实际上还有很多属性用于设置共享文件系统出现的各种情况。这里不再赘述。

你可能感兴趣的:(Spring Integration-File Adapter使用)