From a27b1ec28fa90104d575269e8bd7a16ae75ada19 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 10 Nov 2021 16:03:50 -0500 Subject: [PATCH] Revert method references back to lambdas Turns out Java does cast for the method reference argument before really calling a delegating method. * Revert cast method references (`((ApplicationContextAware) this.handler)::setApplicationContext`) back to lambdas - `context -> ((ApplicationContextAware) this.handler).setApplicationContext(this.applicationContext)` This way the cast is deferred until the lambda is called. --- ...stractSimpleMessageHandlerFactoryBean.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractSimpleMessageHandlerFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractSimpleMessageHandlerFactoryBean.java index 9a4eb90a92..0875571d98 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractSimpleMessageHandlerFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractSimpleMessageHandlerFactoryBean.java @@ -199,18 +199,19 @@ public abstract class AbstractSimpleMessageHandlerFactoryBean ((ApplicationContextAware) this.handler).setApplicationContext(this.applicationContext)) + .acceptIfCondition(this.handler instanceof BeanFactoryAware && getBeanFactory() != null, + getBeanFactory(), + factory -> ((BeanFactoryAware) this.handler).setBeanFactory(factory)) + .acceptIfCondition(this.handler instanceof BeanNameAware && this.beanName != null, this.beanName, + name -> ((BeanNameAware) this.handler).setBeanName(this.beanName)) + .acceptIfCondition(this.handler instanceof ApplicationEventPublisherAware + && this.applicationEventPublisher != null, + this.applicationEventPublisher, + publisher -> ((ApplicationEventPublisherAware) this.handler) + .setApplicationEventPublisher(publisher)); configureOutputChannelIfAny(); Object actualHandler = extractTarget(this.handler); if (actualHandler == null) { @@ -220,11 +221,11 @@ public abstract class AbstractSimpleMessageHandlerFactoryBean ((AbstractMessageProducingHandler) handlerToConfigure).setAsync(asyncValue)) + .acceptIfCondition(this.handler instanceof Orderable && this.order != null, + this.order, theOrder -> ((Orderable) this.handler).setOrder(theOrder)); this.initialized = true; } initializingBean(); @@ -234,10 +235,10 @@ public abstract class AbstractSimpleMessageHandlerFactoryBean ((IntegrationObjectSupport) handlerToConfigure).setComponentName(name)) + .acceptIfNotNull(this.channelResolver, + resolver -> ((IntegrationObjectSupport) handlerToConfigure).setChannelResolver(resolver)); } }