我是Spring的新手,我正在写一个文件适配器,它从输入文件夹读取文件并将文件移动到输出文件夹。我玩了下面的例子,但有一些点我不清楚。春季集成 - 文件适配器
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:file="http://www.springframework.org/schema/integration/file"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/file
http://www.springframework.org/schema/integration/file/spring-integration-file.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
<file:inbound-channel-adapter id="filesIn"
directory="C:\Users\my\Desktop\files\in"
filename-regex="[a-z]+.txt">
<integration:poller id="poller" fixed-delay="5000"/>
</file:inbound-channel-adapter>
<file:file-to-string-transformer input-channel="filesIn" output-channel="strings"/>
<integration:channel id="strings"/>
<integration:service-activator input-channel="strings"
output-channel="filesOut"
ref="handler"/>
<file:outbound-channel-adapter id="filesOut" directory="C:\Users\my\Desktop\files\out"/>
<bean id="handler" class="org.springframework.integration.samples.filecopy.Handler"/>
我有几个关于上述文件的更多问题。
- 我没有对
<integration:channel id="strings"/>
标签清晰的概念。为什么它只是字符串。其他可能的值是什么,可以用来代替strings
。 - 正如我测试
input-channel
的integration:service-activator
和output-channel
的file-to-string-transformer
与<integration:channel id="strings"/>
无关,是正确的吗? handler
用于integration:service-activator
的bean有3种方法。public class Handler { public String handleString(String input) { System.out.println("Copying text: " + input); return input.toUpperCase(); } public File handleFile(File input) { System.out.println("Copying file: " + input.getAbsolutePath()); return input; } public byte[] handleBytes(byte[] input) { System.out.println("Copying " + input.length + " bytes ..."); return new String(input).toUpperCase().getBytes(); } }
而且目前它触发只有一个方法是
handleString(String whichTakesString)
是不是因为<integration:service-activator input-channel="strings"
的?我怎样才能调用其他方法,怎么做。我试图找出很多方法,但仍然没有机会。
感谢您的快速回复,这是非常有用的。 –