【发布时间】:2018-10-12 11:37:21
【问题描述】:
我在 Spring Boot 应用程序中使用标准 Spring @RestController,该应用程序调用 Spring Integration 以启动消息流。据我了解,在这种情况下,与 Spring 集成的挂钩是使用网关 - 似乎有几种不同的方式可以使用 Java DSL 来完成。
我目前有两种不同的工作方式:
- 通过定义一个标有
@MessagingGateway注释的接口。 - 通过实例化
new GatewayProxyFactoryBean(Consumer.class)并设置通道。
这两种方法都感觉有点笨拙——似乎还有第三种更简洁的方法,它允许您不必注释或手动构造 GatewayProxyFactoryBean,而只需使用带有 bean 名称的内置功能接口。来自文档:
@Bean
public IntegrationFlow errorRecovererFlow() {
return IntegrationFlows.from(Function.class, "errorRecovererFunction")
.handle((GenericHandler<?>) (p, h) -> {
throw new RuntimeException("intentional");
}, e -> e.advice(null))
.get();
}
@Autowired
@Qualifier("errorRecovererFunction")
private Function<String, String> errorRecovererFlowGateway;
但是,bean errorRecovererFunction 似乎没有注册,应用程序无法启动。
Field errorRecovererFlowGateway in MyController required a bean of type 'java.util.function.Function' that could not be found.
我错过了什么吗?
提前致谢。
【问题讨论】:
-
有没有机会和我们分享一下 GitHub 上的简单项目,让我们玩和复制?
-
到目前为止一切都很好,我希望你在某个地方有一个
@EnableIntegration,或者这是一个 Spring Boot 应用程序。还要确保控制器和集成流在同一个上下文中。
标签: spring-integration spring-integration-dsl