INT-3330 EnableIntegrationMBeanExport Annotation
JIRA: https://jira.spring.io/browse/INT-3330 INT-3330: Enable SpEL evaluation INT-3330: Polishing for `MBeanExporterHelper` INT-3330: Fix `errorChannel` early access INT-3330: Polishing according PR comments Polishing - copyrights, author, docs
This commit is contained in:
committed by
Gary Russell
parent
1d6e80ecd0
commit
97c270c0e2
@@ -31,9 +31,13 @@ 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.RootBeanDefinition;
|
||||
import org.springframework.integration.channel.MessagePublishingErrorHandler;
|
||||
import org.springframework.integration.channel.NullChannel;
|
||||
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.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
|
||||
/**
|
||||
* A {@link BeanFactoryPostProcessor} implementation that provides default beans for the error handling and task
|
||||
@@ -126,21 +130,19 @@ class DefaultConfiguringBeanFactoryPostProcessor implements BeanFactoryPostProce
|
||||
logger.info("No bean named '" + IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME +
|
||||
"' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.");
|
||||
}
|
||||
RootBeanDefinition errorChannelDef = new RootBeanDefinition();
|
||||
errorChannelDef.setBeanClassName(IntegrationConfigUtils.BASE_PACKAGE
|
||||
+ ".channel.PublishSubscribeChannel");
|
||||
BeanDefinitionHolder errorChannelHolder = new BeanDefinitionHolder(errorChannelDef,
|
||||
IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
|
||||
BeanDefinitionReaderUtils.registerBeanDefinition(errorChannelHolder, registry);
|
||||
BeanDefinitionBuilder loggingHandlerBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
IntegrationConfigUtils.BASE_PACKAGE + ".handler.LoggingHandler");
|
||||
loggingHandlerBuilder.addConstructorArgValue("ERROR");
|
||||
BeanDefinitionBuilder loggingEndpointBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
IntegrationConfigUtils.BASE_PACKAGE + ".endpoint.EventDrivenConsumer");
|
||||
loggingEndpointBuilder.addConstructorArgReference(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
|
||||
loggingEndpointBuilder.addConstructorArgValue(loggingHandlerBuilder.getBeanDefinition());
|
||||
BeanComponentDefinition componentDefinition = new BeanComponentDefinition(
|
||||
loggingEndpointBuilder.getBeanDefinition(), ERROR_LOGGER_BEAN_NAME);
|
||||
registry.registerBeanDefinition(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME,
|
||||
new RootBeanDefinition(PublishSubscribeChannel.class));
|
||||
|
||||
BeanDefinitionBuilder loggingHandlerBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition(LoggingHandler.class).addConstructorArgValue("ERROR");
|
||||
|
||||
BeanDefinitionBuilder loggingEndpointBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition(ConsumerEndpointFactoryBean.class)
|
||||
.addPropertyValue("handler", loggingHandlerBuilder.getBeanDefinition())
|
||||
.addPropertyValue("inputChannelName", IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
|
||||
|
||||
BeanComponentDefinition componentDefinition =
|
||||
new BeanComponentDefinition(loggingEndpointBuilder.getBeanDefinition(), ERROR_LOGGER_BEAN_NAME);
|
||||
BeanDefinitionReaderUtils.registerBeanDefinition(componentDefinition, registry);
|
||||
}
|
||||
|
||||
@@ -152,19 +154,14 @@ class DefaultConfiguringBeanFactoryPostProcessor implements BeanFactoryPostProce
|
||||
logger.info("No bean named '" + IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME +
|
||||
"' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.");
|
||||
}
|
||||
BeanDefinitionBuilder schedulerBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
"org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler");
|
||||
String taskSchedulerPoolSizeExpression = IntegrationProperties.getExpressionFor(IntegrationProperties.TASK_SCHEDULER_POOL_SIZE);
|
||||
schedulerBuilder.addPropertyValue("poolSize", taskSchedulerPoolSizeExpression);
|
||||
schedulerBuilder.addPropertyValue("threadNamePrefix", "task-scheduler-");
|
||||
schedulerBuilder.addPropertyValue("rejectedExecutionHandler", new CallerRunsPolicy());
|
||||
BeanDefinitionBuilder errorHandlerBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
IntegrationConfigUtils.BASE_PACKAGE + ".channel.MessagePublishingErrorHandler");
|
||||
errorHandlerBuilder.addPropertyReference("defaultErrorChannel", IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
|
||||
schedulerBuilder.addPropertyValue("errorHandler", errorHandlerBuilder.getBeanDefinition());
|
||||
BeanComponentDefinition schedulerComponent = new BeanComponentDefinition(
|
||||
schedulerBuilder.getBeanDefinition(), IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME);
|
||||
BeanDefinitionReaderUtils.registerBeanDefinition(schedulerComponent, registry);
|
||||
BeanDefinition scheduler = BeanDefinitionBuilder.genericBeanDefinition(ThreadPoolTaskScheduler.class)
|
||||
.addPropertyValue("poolSize", IntegrationProperties.getExpressionFor(IntegrationProperties.TASK_SCHEDULER_POOL_SIZE))
|
||||
.addPropertyValue("threadNamePrefix", "task-scheduler-")
|
||||
.addPropertyValue("rejectedExecutionHandler", new CallerRunsPolicy())
|
||||
.addPropertyValue("errorHandler", new RootBeanDefinition(MessagePublishingErrorHandler.class))
|
||||
.getBeanDefinition();
|
||||
|
||||
registry.registerBeanDefinition(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, scheduler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ public class IntegrationRegistrar implements ImportBeanDefinitionRegistrar, Bean
|
||||
@Override
|
||||
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
|
||||
this.registerImplicitChannelCreator(registry);
|
||||
this.registerIntegrationConfigurationBeanFactoryPostProcessor(registry);
|
||||
this.registerIntegrationEvaluationContext(registry);
|
||||
this.registerIntegrationProperties(registry);
|
||||
this.registerHeaderChannelRegistry(registry);
|
||||
@@ -89,7 +90,6 @@ public class IntegrationRegistrar implements ImportBeanDefinitionRegistrar, Bean
|
||||
if (importingClassMetadata != null) {
|
||||
this.registerMessagingAnnotationPostProcessors(importingClassMetadata, registry);
|
||||
}
|
||||
this.registerIntegrationConfigurationBeanFactoryPostProcessor(registry);
|
||||
this.registerMessageBuilderFactory(registry);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,13 @@
|
||||
|
||||
package org.springframework.integration.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -26,13 +30,13 @@ import org.springframework.integration.channel.MessagePublishingErrorHandler;
|
||||
import org.springframework.integration.channel.NullChannel;
|
||||
import org.springframework.integration.channel.PublishSubscribeChannel;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.springframework.util.ErrorHandler;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -64,18 +68,22 @@ public class DefaultConfiguringBeanFactoryPostProcessorTests {
|
||||
public void taskSchedulerRegistered() {
|
||||
Object taskScheduler = context.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME);
|
||||
assertEquals(ThreadPoolTaskScheduler.class, taskScheduler.getClass());
|
||||
Object errorHandler = new DirectFieldAccessor(taskScheduler).getPropertyValue("errorHandler");
|
||||
ErrorHandler errorHandler = TestUtils.getPropertyValue(taskScheduler, "errorHandler", ErrorHandler.class);
|
||||
assertEquals(MessagePublishingErrorHandler.class, errorHandler.getClass());
|
||||
Object defaultErrorChannel = new DirectFieldAccessor(errorHandler).getPropertyValue("defaultErrorChannel");
|
||||
MessageChannel defaultErrorChannel = TestUtils.getPropertyValue(errorHandler, "defaultErrorChannel", MessageChannel.class);
|
||||
assertNull(defaultErrorChannel);
|
||||
errorHandler.handleError(new Throwable());
|
||||
defaultErrorChannel = TestUtils.getPropertyValue(errorHandler, "defaultErrorChannel", MessageChannel.class);
|
||||
assertNotNull(defaultErrorChannel);
|
||||
assertEquals(context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME), defaultErrorChannel);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void taskSchedulerNotRegisteredMoreThanOnce() {
|
||||
ClassPathXmlApplicationContext superParentApplicationContext = new ClassPathXmlApplicationContext("superParentApplicationContext.xml", this.getClass());
|
||||
ClassPathXmlApplicationContext parentApplicationContext =
|
||||
ClassPathXmlApplicationContext parentApplicationContext =
|
||||
new ClassPathXmlApplicationContext(new String[]{"org/springframework/integration/config/xml/parentApplicationContext.xml"}, superParentApplicationContext);
|
||||
ClassPathXmlApplicationContext childApplicationContext =
|
||||
ClassPathXmlApplicationContext childApplicationContext =
|
||||
new ClassPathXmlApplicationContext(new String[]{"org/springframework/integration/config/xml/childApplicationContext.xml"}, parentApplicationContext);
|
||||
TaskScheduler parentScheduler = childApplicationContext.getParent().getBean("taskScheduler", TaskScheduler.class);
|
||||
TaskScheduler childScheduler = childApplicationContext.getBean("taskScheduler", TaskScheduler.class);
|
||||
|
||||
Reference in New Issue
Block a user