在我喝助兴酒之前做些探索性工作。
我正在尝试创建一个简单的入站通道适配器来监视新ZIP文件的目录。
为了应付永远存在的“它完成了吗?”问题是,我正在尝试修改发布的这里示例,使其包含一个检查文件修改时间的FileListFilter。
但是,我得到了以下例外:
a boolean result is requiredclass java.util.ArrayList is not assignable to class java.lang.Boolean
at org.springframework.util.Assert.isAssignable(Assert.java:368)
at org.springframework.integration.filter.AbstractMessageProcessingSelector.accept(AbstractMessageProcessingSelector.java:61)
at org.springframework.integration.filter.MessageFilter.handleRequestMessage(MessageFilter.java:103)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:134)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)我用一个基于文件扩展名的简单路由器可以很好地工作,但是当我用这个过滤器替换它时,它就崩溃了。似乎实际的文件列表是断言试图转换为布尔值的内容。
是否不可能在入站适配器和出站适配器之间连接一个过滤器?或者我必须自己在过滤器中将文件移动到目标?(链接示例中的操作方式)
下面是配置:
<int-file:inbound-channel-adapter id="filePoller" directory="file:input" channel="filesChannel" filename-pattern="*.zip">
<int:poller fixed-rate="2000" max-messages-per-poll="10" />
</int-file:inbound-channel-adapter>
<int:filter input-channel="filesChannel" ref="lastModifiedFileFilter" output-channel="zipFilesOut"/>
<bean id="lastModifiedFileFilter" class="FileFilterOnLastModifiedTime">
<property name="timeDifference" value="10000"/>
</bean>
<int-file:outbound-channel-adapter id="zipFilesOut" directory="file:target/output/zip" delete-source-files="true" />下面是过滤器:导入java.io.File;
import org.springframework.integration.file.filters.AbstractFileListFilter;
public class FileFilterOnLastModifiedTime extends AbstractFileListFilter<File> {
Long timeDifference = 1000L;
@Override
protected boolean accept(File file) {
long lastModified = file.lastModified();
long currentTime = System.currentTimeMillis();
return (currentTime - lastModified) > timeDifference ;
}
public void setTimeDifference(Long timeDifference) {
this.timeDifference = timeDifference;
}
}发布于 2015-05-12 13:27:31
您的FileFilterOnLastModifiedTime bean应该使用filter属性提供给入站适配器。
<int-file:inbound-channel-adapter id="filePoller" directory="file:input" channel="zipFilesOut" filename-pattern="*.zip"
filter="lastModifiedFileFilter">
<int:poller fixed-rate="2000" max-messages-per-poll="10" />
</int-file:inbound-channel-adapter>内联<filter/>元素是一个简单的POJO,它接受一些参数并返回一个布尔值。
因为您提供了一个AbstractFileListFilter,所以框架试图调用filterFiles,它接受一个数组并返回一个List,而不是一个布尔值。
https://stackoverflow.com/questions/30191451
复制相似问题