SPR-5507 AbstractJmsListeningContainer now implements SmartLifecycle instead of ApplicationListener.

This commit is contained in:
Mark Fisher 2009-11-10 04:52:56 +00:00
parent a7c1f6b730
commit a15a9600b7
2 changed files with 13 additions and 15 deletions

View File

@ -25,10 +25,7 @@ import javax.jms.JMSException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.Lifecycle;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.SmartLifecycle;
import org.springframework.jms.JmsException;
import org.springframework.jms.connection.ConnectionFactoryUtils;
import org.springframework.jms.support.JmsUtils;
@ -62,7 +59,7 @@ import org.springframework.util.ClassUtils;
* @see #doShutdown()
*/
public abstract class AbstractJmsListeningContainer extends JmsDestinationAccessor
implements Lifecycle, ApplicationListener<ApplicationEvent>, BeanNameAware, DisposableBean {
implements SmartLifecycle, BeanNameAware, DisposableBean {
private String clientId;
@ -115,6 +112,10 @@ public abstract class AbstractJmsListeningContainer extends JmsDestinationAccess
this.autoStartup = autoStartup;
}
public boolean isAutoStartup() {
return this.autoStartup;
}
public void setBeanName(String beanName) {
this.beanName = beanName;
}
@ -137,12 +138,6 @@ public abstract class AbstractJmsListeningContainer extends JmsDestinationAccess
initialize();
}
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ContextRefreshedEvent && this.autoStartup) {
this.start();
}
}
/**
* Validate the configuration of this container.
* <p>The default implementation is empty. To be overridden in subclasses.

View File

@ -35,8 +35,7 @@ import org.easymock.internal.AlwaysMatcher;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.task.TaskExecutor;
import org.springframework.jms.StubQueue;
import org.springframework.util.ErrorHandler;
@ -130,7 +129,9 @@ public class SimpleMessageListenerContainerTests extends AbstractMessageListener
this.container.setMessageListener(new TestMessageListener());
this.container.setAutoStartup(false);
this.container.afterPropertiesSet();
this.container.onApplicationEvent(new ContextRefreshedEvent(new StaticApplicationContext()));
GenericApplicationContext context = new GenericApplicationContext();
context.getBeanFactory().registerSingleton("messageListenerContainer", this.container);
context.refresh();
mockMessageConsumer.verify();
mockSession.verify();
@ -181,7 +182,9 @@ public class SimpleMessageListenerContainerTests extends AbstractMessageListener
this.container.setMessageListener(new TestMessageListener());
this.container.afterPropertiesSet();
this.container.onApplicationEvent(new ContextRefreshedEvent(new StaticApplicationContext()));
GenericApplicationContext context = new GenericApplicationContext();
context.getBeanFactory().registerSingleton("messageListenerContainer", this.container);
context.refresh();
mockMessageConsumer.verify();
mockSession.verify();