I'm using a standard Spring @RestController
inside a Spring Boot app that calls into Spring Integration to initiate a messaging flow. As I understand it, the hook into Spring Integration in this instance is to use a Gateway - there seems to be a few different ways that this can be done using the Java DSL.
I currently have this working in 2 different ways:
- by defining an interface marked with the
@MessagingGateway
annotation. - by instantiating a
new GatewayProxyFactoryBean(Consumer.class)
and setting the channel.
Both of these feel a bit clunky - there appears to be a third, cleaner way, that allows you to not have to annotate or manually construct a GatewayProxyFactoryBean, and simply use a built-in Functional interface with a bean name. From the docs:
@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;
However, the bean errorRecovererFunction
does not appear to get registered and the application fails to start.
Field errorRecovererFlowGateway in MyController required a bean of type 'java.util.function.Function' that could not be found.
Am I missing something here?
Thanks in advance.
@EnableIntegration
somewhere or this is a Spring Boot application. Also be sure that controller and Integration flow are in the same context. - Artem Bilan