3

我有一个出站通道适配器,相关配置如下所示。

<int:outbound-channel-adapter channel="foo-fileChannel" ref="foo-handlerTarget" method="handleFeedFile">
    <int:poller fixed-delay="5000" receive-timeout="1000" max-messages-per-poll="10" />
</int:outbound-channel-adapter>
<int:channel id="foo-fileChannel">
    <int:queue />
</int:channel>


<bean id="foo-handlerTarget" class="com.abc.FooFeedHandlerImpl">
    <property name="fooDescriptorFile" value="${feed.foo.fooDescriptorFile}" />
    <property name="fileIdRegex" ref="foo-fileRegex" />
    <property name="processId" value="${feed.processId}" />
    <property name="workingLocation" value="${feed.foo.workingLocation}" />
    <property name="remoteLocation" value="${feed.foo.remoteLocation}" />
    <property name="stalenessThreshold" value="${feed.foo.stalenessThreshold}" />
</bean>

而在 FooFeedHandlerImpl...

public void handleFeedFile(File retrievedFile) {
    handleFeedFile(retrievedFile, null);
}


public void handleFeedFile(File retrievedFile, String processKey) {
    if (isHandlerForFileName(retrievedFile.getName())) {
        processFeed(retrievedFile, processKey);
    }
}

问题:

通道适配器调用了哪个 handleFeedFile 方法?

当我使用 Spring 集成在应用程序代码中调用方法时,方法参数是如何确定的?

谢谢你的帮助!

编辑:

我在本地运行我的进程(下载了本地 SFTP 服务器 - http://www.coreftp.com/server/index.html)并确定handleFeedFile(File file)调用了该方法。

4

2 回答 2

3

您可能想参考F.6 消息映射规则和约定

在确定适当的映射方面,多个参数可能会产生很多歧义。一般建议是使用@Payload 和/或@Header/@Headers 注释您的方法参数。下面是一些模棱两可条件的示例,这些条件会导致引发异常。

和:

多种方法:

具有多个方法的消息处理程序基于上述相同的规则进行映射,但是某些场景可能看起来仍然令人困惑。

如果您无法注释您的目标方法,那么您可以使用 SpEL 表达式来调用您想要的方法:

3.3.2 配置出站通道适配器

与许多其他 Spring Integration 组件一样,它也提供对 SpEL 表达式评估的支持。要使用 SpEL,请通过 'expression' 属性提供表达式字符串,而不是提供用于 bean 上的方法调用的 'ref' 和 'method' 属性。当计算表达式时,它遵循与方法调用相同的约定,其中:每当计算结果为非空值时,an 的表达式将生成一条消息,而 an 的表达式必须等效于返回 void 的方法调用。

于 2015-05-02T23:45:51.407 回答
1

根据有关 Spring 集成的文档,您的案例中的 POJO (bean foo-handlerTarget) 将使用Message包含有效负载的对象进行调用。你执行过你的代码吗?我希望它会生成一个NoSuchMethodError.

你需要一个

public void handleFeedFile(Message<?> message);

方法。

于 2015-05-01T21:45:09.907 回答