【发布时间】:2013-01-08 22:57:03
【问题描述】:
为什么即使在我指定了requires-reply="false" 之后,我仍会收到以下异常
例外
org.springframework.integration.support.channel.ChannelResolutionException:没有可用的输出通道或replyChannel标头
配置
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsd">
<int:channel id="inChannel">
</int:channel>
<bean id="upperService" class="sipackage.service.UppercaseService"></bean>
<int:service-activator requires-reply="false" input-channel="inChannel" ref="upperService" method="toUpper"></int:service-activator>
</beans>
JUnit
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/META-INF/spring/integration/sample.xml"})
public class ChannelTest {
@Autowired MessageChannel inChannel;
@Test
public void test() {
boolean sendOutcome=inChannel.send(MessageBuilder.withPayload("Hello, there 1!").build());
assertTrue(sendOutcome);
sendOutcome=inChannel.send(MessageBuilder.withPayload("Hello, there 2!").build());
assertTrue(sendOutcome);
}
}
服务
public class UppercaseService {
public String toUpper(String msg)
{
return msg.toUpperCase();
}
}
【问题讨论】:
-
你的意思是客户端对下游服务的返回值不感兴趣?使用 output-channel="nullChannel"; requires-reply 应该用于返回 void 或 null afaik 的方法
-
谢谢,但我知道您提出的两种解决方案。我认为 requires-reply 标志是为了忽略返回的值。如果不是,这个标志的目的可能是什么?
-
requires-reply 默认为 false。将下游组件的 requires-reply 属性设置为“true”,以确保在下游组件内部返回 null 后立即通过抛出异常产生及时响应。
标签: java spring spring-integration