我是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"
的?我怎樣才能調用其他方法,怎麼做。我試圖找出很多方法,但仍然沒有機會。
感謝您的快速回復,這是非常有用的。 –