Spring Integration Http with Spring Boot和@RequestMapping

时间:2015-02-16 21:59:54

标签: spring-boot spring-integration

我尝试使用Spring Integration HTTP开发SpringBoot Rest服务器 - > inboundGateway。

我有一个Controller,用“@Controller”和“@RequestMapping”注释,并尝试创建以下流程:

GET Request“/” - >频道:httpRequestChannel - >运行IndexController - >频道:httpReplyChannel - >回到浏览器

但它不起作用。

我的集成Xml:

<int:channel id="httpRequestChannel">
  <int:interceptors>
    <int:wire-tap channel="logHttpRequestChannel" />
  </int:interceptors>
</int:channel>

<int:channel id="httpReplyChannel">
  <int:interceptors>
    <int:wire-tap channel="logHttpReplyChannel" />
  </int:interceptors>
</int:channel>

<int:logging-channel-adapter id="logHttpRequestChannel" level="INFO" logger-name="httpRequestChannel" log-full-message="true" />

<int:logging-channel-adapter id="logHttpReplyChannel" level="INFO" logger-name="httpReplyChannel" log-full-message="true" />

<int-http:inbound-gateway id="inboundGateway"
    request-channel="httpRequestChannel" reply-channel="httpReplyChannel"
    auto-startup="true" supported-methods="GET" path="/">
    <int-http:request-mapping produces="application/json" />
</int-http:inbound-gateway>

错误是:

Dispatcher has no subscribers

但在我看来,控制器应该是通过RequestMapping Annotation的订阅者......

我上传了一个示例github项目:https://github.com/marcelalburg/spring-boot-integration-rest-server

谢谢你的帮助 烫发

更新

您好,

我在文档中看到了一些内容:

  

解析HTTP入站网关或HTTP入站通道适配器会注册IntegrationRequestMappingHandlerMapping类型的integrationRequestMappingHandlerMapping bean,以防万一没有注册。 HandlerMapping的这个特定实现将其逻辑委托给RequestMappingInfoHandlerMapping。该实现提供了与Spring MVC中的org.springframework.web.bind.annotation.RequestMapping批注提供的功能类似的功能。

所以,我改变了以下内容:

    <int-http:inbound-gateway id="indexGateway"
    request-channel="httpRequestChannel" reply-channel="httpReplyChannel"
    auto-startup="true" supported-methods="GET" path="/, /test" reply-timeout="100" />

和我的控制器

@ServiceActivator( inputChannel = "httpRequestChannel", outputChannel = "httpReplyChannel" )
@RequestMapping( value = "/", method = RequestMethod.GET, produces = "application/json" )
public String testGateway( LinkedMultiValueMap payload, @Headers Map<String, Object> headerMap )
{
    // IntegrationRequestMappingHandlerMapping

    System.out.println( "Starting process the message [reciveing]" );

    return "{HelloMessage: \"Hello\"}";
}

@ServiceActivator( inputChannel = "httpRequestChannel", outputChannel = "httpReplyChannel" )
@RequestMapping( value = "/test", method = RequestMethod.GET, produces = "application/json" )
public String testGateway2( LinkedMultiValueMap payload, @Headers Map<String, Object> headerMap )
{
    // IntegrationRequestMappingHandlerMapping

    System.out.println( "Starting process the message [reciveing]" );

    return "{HelloMessage: \"Test\"}";
}

现在,我得到一个回复​​,但它返回随机的“测试”和“你好”......

由于

1 个答案:

答案 0 :(得分:2)

没有;你似乎有一个基本的误解。

使用Spring Integration,入站网关替换 @Controller,并将入站(可能已转换)对象作为消息的有效负载发送到requestChannel。< / p>

其他一些组件(不是控制器)订阅该频道以接收该消息。

因此,您可以将POJO配置为@Controller,也可以将方法注释为<service-activator input-channel="httpRequestChannel" .../>,而不是配置@ServiceActivator

然后它将使用该消息,并且可选地将回复发送到输出通道(省略输出通道将使其被路由回网关)。

有关示例,请参阅http sample