0

Is there an elegant way to define a single @MessageEndpoint bean with multiple @ServiceActivator methods (or something like that), where the methods' argument types are implicitly used as a payload-type-filter?

The idea is to have a single service endpoint which can handle different payload types slightly different without much effort by dispatching on the argument type, which alleviates the implementation of additional service methods down the line.

I'm aware of Google Guava's EventBus, which dispatches event objects to any registered @Subscribe method with a matching argument type. I'm currently using this approach, but I was wondering if this was also (kinda) possible with Spring Integration.

4

1 回答 1

0

在 XML 中,只要没有歧义, <service-activator ... ref="foo" />(没有)将解析为基于有效负载类型的方法。method

使用 4.0 或更高版本,您可以使用...

@Bean
@ServiceActivator(...)
public MessageHandler foo() {
    ...
}

ServiceHandlingFactoryBean将带有集合的 a 返回targetObject到您的 POJO(同样,没有方法名称)。

请注意,在这种情况下,您必须outputChannel在工厂 bean 上设置 (outputChannel注释上的属性被忽略)。

于 2014-09-25T11:02:36.033 回答