MessageBus now registers endpoints and source adapters (and starts if its autoStartup property is set to "true") after receiving a ContextRefreshedEvent rather than the excessively eager start during the 'setApplicationContext' callback (INT-196).
This commit is contained in:
@@ -27,6 +27,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.PollingSourceAdapter;
|
||||
import org.springframework.integration.adapter.jms.JmsMessageDrivenSourceAdapter;
|
||||
@@ -140,7 +141,7 @@ public class JmsSourceAdapterParserTests {
|
||||
new ClassPathXmlApplicationContext("pollingAdapterWithDestinationOnly.xml", this.getClass());
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals(BeanCreationException.class, e.getCause().getClass());
|
||||
assertEquals(NoSuchBeanDefinitionException.class, e.getCause().getClass());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,10 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.SourceAdapter;
|
||||
import org.springframework.integration.channel.ChannelRegistry;
|
||||
@@ -64,7 +67,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MessageBus implements ChannelRegistry, EndpointRegistry, ApplicationContextAware, Lifecycle {
|
||||
public class MessageBus implements ChannelRegistry, EndpointRegistry, ApplicationContextAware, ApplicationListener, Lifecycle {
|
||||
|
||||
public static final String ERROR_CHANNEL_NAME = "errorChannel";
|
||||
|
||||
@@ -109,11 +112,6 @@ public class MessageBus implements ChannelRegistry, EndpointRegistry, Applicatio
|
||||
+ "' is allowed per ApplicationContext.");
|
||||
}
|
||||
this.registerChannels(applicationContext);
|
||||
this.registerEndpoints(applicationContext);
|
||||
this.registerSourceAdapters(applicationContext);
|
||||
if (this.autoStartup) {
|
||||
this.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -476,4 +474,15 @@ public class MessageBus implements ChannelRegistry, EndpointRegistry, Applicatio
|
||||
}
|
||||
}
|
||||
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
if (event instanceof ContextRefreshedEvent) {
|
||||
ApplicationContext context = ((ContextRefreshedEvent) event).getApplicationContext();
|
||||
this.registerEndpoints(context);
|
||||
this.registerSourceAdapters(context);
|
||||
if (this.autoStartup) {
|
||||
this.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user