Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
import org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor;
import org.springframework.aop.support.NameMatchMethodPointcut;
import org.springframework.aop.support.NameMatchMethodPointcutAdvisor;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionValidationException;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.ResolvableType;
Expand Down Expand Up @@ -120,34 +121,27 @@ public abstract class AbstractMethodAnnotationPostProcessor<T extends Annotation

protected final ConfigurableListableBeanFactory beanFactory; // NOSONAR

protected final BeanDefinitionRegistry definitionRegistry; // NOSONAR

protected final ConversionService conversionService; // NOSONAR

protected final DestinationResolver<MessageChannel> channelResolver; // NOSONAR

protected final Class<T> annotationType; // NOSONAR

protected final Disposables disposables; // NOSONAR

@SuppressWarnings(UNCHECKED)
public AbstractMethodAnnotationPostProcessor(ConfigurableListableBeanFactory beanFactory) {
Assert.notNull(beanFactory, "'beanFactory' must not be null");
this.messageHandlerAttributes.add(SEND_TIMEOUT_ATTRIBUTE);
this.beanFactory = beanFactory;
this.definitionRegistry = (BeanDefinitionRegistry) beanFactory;
this.conversionService = this.beanFactory.getConversionService() != null
? this.beanFactory.getConversionService()
: DefaultConversionService.getSharedInstance();
this.channelResolver = ChannelResolverUtils.getChannelResolver(beanFactory);
this.annotationType =
(Class<T>) GenericTypeResolver.resolveTypeArgument(this.getClass(),
MethodAnnotationPostProcessor.class);
Disposables disposablesBean = null;
try {
disposablesBean = beanFactory.getBean(Disposables.class);
}
catch (@SuppressWarnings("unused") Exception e) {
// NOSONAR - only for test cases
}
this.disposables = disposablesBean;
}

@Override
Expand Down Expand Up @@ -187,23 +181,19 @@ public Object postProcess(Object bean, String beanName, Method method, List<Anno
}

private MessageHandler registerHandlerBean(String beanName, Method method, final MessageHandler handler) {
MessageHandler handlerBean = handler;
String handlerBeanName = generateHandlerBeanName(beanName, method);
if (handlerBean instanceof ReplyProducingMessageHandlerWrapper
if (handler instanceof ReplyProducingMessageHandlerWrapper
&& StringUtils.hasText(MessagingAnnotationUtils.endpointIdValue(method))) {
handlerBeanName = handlerBeanName + ".wrapper";
}
if (handlerBean instanceof IntegrationObjectSupport) {
((IntegrationObjectSupport) handlerBean).setComponentName(
if (handler instanceof IntegrationObjectSupport) {
((IntegrationObjectSupport) handler).setComponentName(
handlerBeanName.substring(0,
handlerBeanName.indexOf(IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX)));
}
this.beanFactory.registerSingleton(handlerBeanName, handler);
handlerBean = (MessageHandler) this.beanFactory.initializeBean(handlerBean, handlerBeanName);
if (handlerBean instanceof DisposableBean && this.disposables != null) {
this.disposables.add((DisposableBean) handlerBean);
}
return handlerBean;
this.definitionRegistry.registerBeanDefinition(handlerBeanName,
new RootBeanDefinition(MessageHandler.class, () -> handler));
return this.beanFactory.getBean(handlerBeanName, MessageHandler.class);
}

private void orderable(Method method, MessageHandler handler) {
Expand Down Expand Up @@ -355,12 +345,9 @@ protected AbstractEndpoint createEndpoint(MessageHandler handler, @SuppressWarni
}
catch (DestinationResolutionException e) {
if (e.getCause() instanceof NoSuchBeanDefinitionException) {
inputChannel = new DirectChannel();
this.beanFactory.registerSingleton(inputChannelName, inputChannel);
inputChannel = (MessageChannel) this.beanFactory.initializeBean(inputChannel, inputChannelName);
if (this.disposables != null) {
this.disposables.add((DisposableBean) inputChannel);
}
this.definitionRegistry.registerBeanDefinition(inputChannelName,
new RootBeanDefinition(DirectChannel.class, DirectChannel::new));
inputChannel = this.beanFactory.getBean(inputChannelName, MessageChannel.class);
}
else {
throw e;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationUtils;
Expand Down Expand Up @@ -122,12 +123,9 @@ else if (ClassUtils.KOTLIN_FUNCTION_0_INVOKE_METHOD != null) {
methodInvokingMessageSource.setObject(bean);
methodInvokingMessageSource.setMethod(method);
String messageSourceBeanName = generateHandlerBeanName(beanName, method);
this.beanFactory.registerSingleton(messageSourceBeanName, methodInvokingMessageSource);
messageSource = (MessageSource<?>) this.beanFactory
.initializeBean(methodInvokingMessageSource, messageSourceBeanName);
if (this.disposables != null) {
this.disposables.add(methodInvokingMessageSource);
}
this.definitionRegistry.registerBeanDefinition(messageSourceBeanName,
new RootBeanDefinition(MethodInvokingMessageSource.class, () -> methodInvokingMessageSource));
messageSource = this.beanFactory.getBean(messageSourceBeanName, MessageSource.class);
}
return messageSource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.annotation.Splitter;
import org.springframework.integration.annotation.Transformer;
import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.util.MessagingAnnotationUtils;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -104,11 +103,6 @@ protected ConfigurableListableBeanFactory getBeanFactory() {
@Override
public void afterPropertiesSet() {
Assert.notNull(this.beanFactory, "BeanFactory must not be null");
if (!this.beanFactory.containsBeanDefinition(IntegrationContextUtils.DISPOSABLES_BEAN_NAME)) {
((BeanDefinitionRegistry) this.beanFactory)
.registerBeanDefinition(IntegrationContextUtils.DISPOSABLES_BEAN_NAME,
new RootBeanDefinition(Disposables.class, Disposables::new));
}
this.postProcessors.put(Filter.class, new FilterAnnotationPostProcessor(this.beanFactory));
this.postProcessors.put(Router.class, new RouterAnnotationPostProcessor(this.beanFactory));
this.postProcessors.put(Transformer.class, new TransformerAnnotationPostProcessor(this.beanFactory));
Expand Down Expand Up @@ -224,25 +218,28 @@ protected void processAnnotationTypeOnMethod(Object bean, String beanName, Metho
}
}

@SuppressWarnings("unchecked")
private void postProcessMethodAndRegisterEndpointIfAny(Object bean, String beanName, Method method,
Class<? extends Annotation> annotationType, List<Annotation> annotations,
MethodAnnotationPostProcessor<?> postProcessor, Method targetMethod) {

Object result = postProcessor.postProcess(bean, beanName, targetMethod, annotations);
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
BeanDefinitionRegistry definitionRegistry = (BeanDefinitionRegistry) beanFactory;
if (result instanceof AbstractEndpoint) {
AbstractEndpoint endpoint = (AbstractEndpoint) result;
String autoStartup = MessagingAnnotationUtils.resolveAttribute(annotations, "autoStartup",
String.class);
if (StringUtils.hasText(autoStartup)) {
autoStartup = getBeanFactory().resolveEmbeddedValue(autoStartup);
autoStartup = beanFactory.resolveEmbeddedValue(autoStartup);
if (StringUtils.hasText(autoStartup)) {
endpoint.setAutoStartup(Boolean.parseBoolean(autoStartup));
}
}

String phase = MessagingAnnotationUtils.resolveAttribute(annotations, "phase", String.class);
if (StringUtils.hasText(phase)) {
phase = getBeanFactory().resolveEmbeddedValue(phase);
phase = beanFactory.resolveEmbeddedValue(phase);
if (StringUtils.hasText(phase)) {
endpoint.setPhase(Integer.parseInt(phase));
}
Expand All @@ -255,8 +252,9 @@ private void postProcessMethodAndRegisterEndpointIfAny(Object bean, String beanN

String endpointBeanName = generateBeanName(beanName, method, annotationType);
endpoint.setBeanName(endpointBeanName);
getBeanFactory().registerSingleton(endpointBeanName, endpoint);
getBeanFactory().initializeBean(endpoint, endpointBeanName);
definitionRegistry.registerBeanDefinition(endpointBeanName,
new RootBeanDefinition((Class<AbstractEndpoint>) endpoint.getClass(), () -> endpoint));
beanFactory.getBean(endpointBeanName);
}
}

Expand Down

This file was deleted.