Search code examples
spring-bootspring-integrationaopspring-aopgateway

Spring Boot + Spring Integration Java DSL + AOP : Fails to proxy the Gateway interface


Hi I have a spring boot application, which starts a spring integration flow, through a gateway interface, using Java DSL. Everything works fine on its own. I added AOP to capture exceptions, with @EnableAspectJAutoProxy(proxyTargetClass = true)

At this stage, it gives the error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobInitiator': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.sun.proxy.$Proxy54]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy54

When I remove the proxyTargetClass = true, it works but the advices are not triggered.

Any help? Is there a way to start the spring integration flow without a gateway?


Solution

  • There is no class associated with the gateway Proxy so you can't advise it.

    Is there a way to start the spring integration flow without a gateway?

    Instead of using the gateway, declare a bean of type MessagingTemplate and use template.sendAndReceive(someMessage) or template.convertSendAndReceive(somePojo) instead. See here.

    (The gateway uses a MessagingTemplate internally; the gateway unwraps a MessagingException and throws the cause, the template does not).

    It also does not support an error channel.

    To get closer to the gateway functionality, you can subclass MessagingGatewaySupport and invoke its sendAndReceive() method(s).