【发布时间】:2017-06-15 15:43:51
【问题描述】:
在我的项目中,我将有两个输入参数相同但响应不同的入站网关。每个网关都在不同的 xml 中声明。问题是当我调用 gateway1 时,它转到 xml2 而不是 xml1。 我们应该如何处理。在同一个接口中有两个网关
public interface MessageGateway {
@Gateway(requestChannel="requestChannel1")
@Payload("#args")
public Response1 invoke(Bean bean) throws Exception;
@Gateway(requestChannel="requestChannel2")
@Payload("#args")
public List<Response2> invoke2(Bean bean) throws Exception;
}
在 xml1 中
<int:gateway id="invoke" default-request-channel="requestChannel1" default-reply-channel="finalResult"
service-interface="<class name>" error-channel="errorChannel" default-reply-timeout="6000"/>
<int:channel id="errorChannel"/>
在 xml2 中
<int:gateway id="invoke1" default-request-channel="requestChannel2" default-reply-channel="finalResult"
service-interface="<class name>" error-channel="errorChannel" default-reply-timeout="6000"/>
<int:channel id="errorChannel"/>
我从另一个系统调用网关。所以我自动装配网关接口并调用方法。
根据 Gary 的评论添加自动装配
@Autowired
private MessageGateway gateway;
//calling
gateway.invoke(bean);
【问题讨论】:
-
显示两个网关的自动装配。
-
最好将方法放在不同的接口中以避免混淆。使用此配置,两个网关都有 2 种方法。
-
自动装配应该失败 - 你有 2 个 bean
invoke和invoke1。 Spring 不知道如何为自动布线选择哪一种。您要么只需要一个<gateway/>,要么将方法放在不同的接口上。
标签: spring spring-integration gateway