为什么我收到我指定requires-reply="false"
Spring集成:服务激活需要回复=“假”的使用
异常
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”; require-reply应该用于返回void或null的方法afaik –
谢谢,但我知道您提供的两种解决方案。我认为require-reply标志是为了忽略返回的值。如果不是这个标志的目的可能是什么? –
默认情况下require-reply为false。将下游组件的requires-reply属性设置为“true”,以确保只要下游组件在内部返回null,就立即引发抛出异常的响应。 –