diff --git a/gradle.properties b/gradle.properties index f887faa386..0ba31e7788 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ version=5.5.7-SNAPSHOT -org.gradle.jvmargs=-Xms512m -Xmx4g -XX:MaxPermSize=1024m -XX:MaxMetaspaceSize=1g -Dkotlin.daemon.jvm.options="-Xmx1g --illegal-access=permit" -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx4g -Dkotlin.daemon.jvm.options="-Xmx1g --illegal-access=permit" -Dfile.encoding=UTF-8 org.gradle.caching=true org.gradle.parallel=true kotlin.stdlib.default.dependency=false diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java index 5f8898608f..32131a9c64 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java @@ -35,7 +35,6 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; -import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.core.log.LogAccessor; import org.springframework.integration.channel.ChannelUtils; @@ -46,14 +45,9 @@ import org.springframework.integration.channel.PublishSubscribeChannel; import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.context.IntegrationProperties; import org.springframework.integration.handler.LoggingHandler; -import org.springframework.integration.handler.support.CollectionArgumentResolver; -import org.springframework.integration.handler.support.MapArgumentResolver; -import org.springframework.integration.handler.support.PayloadExpressionArgumentResolver; -import org.springframework.integration.handler.support.PayloadsArgumentResolver; import org.springframework.integration.json.JsonNodeWrapperToJsonNodeConverter; import org.springframework.integration.json.JsonPathUtils; import org.springframework.integration.support.DefaultMessageBuilderFactory; -import org.springframework.integration.support.NullAwarePayloadArgumentResolver; import org.springframework.integration.support.SmartLifecycleRoleController; import org.springframework.integration.support.channel.BeanFactoryChannelResolver; import org.springframework.integration.support.channel.ChannelResolverUtils; @@ -61,7 +55,6 @@ import org.springframework.integration.support.converter.ConfigurableCompositeMe import org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter; import org.springframework.integration.support.json.JacksonPresent; import org.springframework.integration.support.utils.IntegrationUtils; -import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.util.ClassUtils; @@ -483,32 +476,11 @@ public class DefaultConfiguringBeanFactoryPostProcessor } private static BeanDefinitionBuilder createMessageHandlerMethodFactoryBeanDefinition(boolean listCapable) { - return BeanDefinitionBuilder.genericBeanDefinition(DefaultMessageHandlerMethodFactory.class, - DefaultMessageHandlerMethodFactory::new) - .addPropertyReference("messageConverter", - IntegrationContextUtils.ARGUMENT_RESOLVER_MESSAGE_CONVERTER_BEAN_NAME) - .addPropertyValue("customArgumentResolvers", buildArgumentResolvers(listCapable)); - } - - private static ManagedList buildArgumentResolvers(boolean listCapable) { - ManagedList resolvers = new ManagedList<>(); - resolvers.add(new RootBeanDefinition(PayloadExpressionArgumentResolver.class)); - BeanDefinitionBuilder builder = - BeanDefinitionBuilder.genericBeanDefinition(NullAwarePayloadArgumentResolver.class); - builder.addConstructorArgReference(IntegrationContextUtils.ARGUMENT_RESOLVER_MESSAGE_CONVERTER_BEAN_NAME); - // TODO Validator ? - resolvers.add(builder.getBeanDefinition()); - resolvers.add(new RootBeanDefinition(PayloadsArgumentResolver.class)); - - if (listCapable) { - resolvers.add( - BeanDefinitionBuilder.genericBeanDefinition(CollectionArgumentResolver.class) - .addConstructorArgValue(true) - .getBeanDefinition()); - } - - resolvers.add(new RootBeanDefinition(MapArgumentResolver.class)); - return resolvers; + return BeanDefinitionBuilder.genericBeanDefinition(MessageHandlerMethodFactoryCreatingFactoryBean.class, + () -> new MessageHandlerMethodFactoryCreatingFactoryBean(listCapable)) + .addConstructorArgValue(listCapable) + .addPropertyReference("argumentResolverMessageConverter", + IntegrationContextUtils.ARGUMENT_RESOLVER_MESSAGE_CONVERTER_BEAN_NAME); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/MessageHandlerMethodFactoryCreatingFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/MessageHandlerMethodFactoryCreatingFactoryBean.java new file mode 100644 index 0000000000..eb4b5aed96 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/MessageHandlerMethodFactoryCreatingFactoryBean.java @@ -0,0 +1,109 @@ +/* + * Copyright 2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.config; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.integration.handler.support.CollectionArgumentResolver; +import org.springframework.integration.handler.support.MapArgumentResolver; +import org.springframework.integration.handler.support.PayloadExpressionArgumentResolver; +import org.springframework.integration.handler.support.PayloadsArgumentResolver; +import org.springframework.integration.support.NullAwarePayloadArgumentResolver; +import org.springframework.messaging.converter.MessageConverter; +import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory; +import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory; +import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver; + +/** + * The {@link FactoryBean} for creating integration-specific {@link MessageHandlerMethodFactory} instance. + * It adds these custom {@link HandlerMethodArgumentResolver}s in the order: + * + * + * @author Artyem Bilan + * + * @since 5.5.7 + */ +class MessageHandlerMethodFactoryCreatingFactoryBean + implements FactoryBean, BeanFactoryAware { + + private final boolean listCapable; + + MessageConverter argumentResolverMessageConverter; + + private BeanFactory beanFactory; + + MessageHandlerMethodFactoryCreatingFactoryBean(boolean listCapable) { + this.listCapable = listCapable; + } + + public void setArgumentResolverMessageConverter(MessageConverter argumentResolverMessageConverter) { + this.argumentResolverMessageConverter = argumentResolverMessageConverter; + } + + @Override + public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + this.beanFactory = beanFactory; + } + + @Override + public Class getObjectType() { + return MessageHandlerMethodFactory.class; + } + + @Override + public MessageHandlerMethodFactory getObject() throws Exception { + DefaultMessageHandlerMethodFactory handlerMethodFactory = new DefaultMessageHandlerMethodFactory(); + handlerMethodFactory.setBeanFactory(this.beanFactory); + handlerMethodFactory.setMessageConverter(this.argumentResolverMessageConverter); + handlerMethodFactory.setCustomArgumentResolvers(buildArgumentResolvers(this.listCapable)); + handlerMethodFactory.afterPropertiesSet(); + return handlerMethodFactory; + } + + private List buildArgumentResolvers(boolean listCapable) throws Exception { + List resolvers = new ArrayList<>(); + resolvers.add(new PayloadExpressionArgumentResolver()); + resolvers.add(new NullAwarePayloadArgumentResolver(this.argumentResolverMessageConverter)); + resolvers.add(new PayloadsArgumentResolver()); + if (listCapable) { + resolvers.add(new CollectionArgumentResolver(true)); + } + resolvers.add(new MapArgumentResolver()); + for (HandlerMethodArgumentResolver resolver : resolvers) { + if (resolver instanceof BeanFactoryAware) { + ((BeanFactoryAware) resolver).setBeanFactory(this.beanFactory); + } + if (resolver instanceof InitializingBean) { + ((InitializingBean) resolver).afterPropertiesSet(); + } + } + return resolvers; + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java index 51656800a5..6bfd580e82 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java @@ -110,6 +110,10 @@ public abstract class IntegrationContextUtils { public static final String ARGUMENT_RESOLVER_MESSAGE_CONVERTER_BEAN_NAME = "integrationArgumentResolverMessageConverter"; + /** + * @deprecated since 5.5.7 - out of use. + */ + @Deprecated public static final String DISPOSABLES_BEAN_NAME = "integrationDisposableAutoCreatedBeans"; public static final String MESSAGE_HANDLER_FACTORY_BEAN_NAME = "integrationMessageHandlerMethodFactory";