Skip to content

Commit a15a960

Browse files
committedNov 10, 2009
SPR-5507 AbstractJmsListeningContainer now implements SmartLifecycle instead of ApplicationListener.
1 parent a7c1f6b commit a15a960

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed
 

‎org.springframework.jms/src/main/java/org/springframework/jms/listener/AbstractJmsListeningContainer.java

+6-11
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525

2626
import org.springframework.beans.factory.BeanNameAware;
2727
import org.springframework.beans.factory.DisposableBean;
28-
import org.springframework.context.ApplicationEvent;
29-
import org.springframework.context.ApplicationListener;
30-
import org.springframework.context.Lifecycle;
31-
import org.springframework.context.event.ContextRefreshedEvent;
28+
import org.springframework.context.SmartLifecycle;
3229
import org.springframework.jms.JmsException;
3330
import org.springframework.jms.connection.ConnectionFactoryUtils;
3431
import org.springframework.jms.support.JmsUtils;
@@ -62,7 +59,7 @@
6259
* @see #doShutdown()
6360
*/
6461
public abstract class AbstractJmsListeningContainer extends JmsDestinationAccessor
65-
implements Lifecycle, ApplicationListener<ApplicationEvent>, BeanNameAware, DisposableBean {
62+
implements SmartLifecycle, BeanNameAware, DisposableBean {
6663

6764
private String clientId;
6865

@@ -115,6 +112,10 @@ public void setAutoStartup(boolean autoStartup) {
115112
this.autoStartup = autoStartup;
116113
}
117114

115+
public boolean isAutoStartup() {
116+
return this.autoStartup;
117+
}
118+
118119
public void setBeanName(String beanName) {
119120
this.beanName = beanName;
120121
}
@@ -137,12 +138,6 @@ public void afterPropertiesSet() {
137138
initialize();
138139
}
139140

140-
public void onApplicationEvent(ApplicationEvent event) {
141-
if (event instanceof ContextRefreshedEvent && this.autoStartup) {
142-
this.start();
143-
}
144-
}
145-
146141
/**
147142
* Validate the configuration of this container.
148143
* <p>The default implementation is empty. To be overridden in subclasses.

‎org.springframework.jms/src/test/java/org/springframework/jms/listener/SimpleMessageListenerContainerTests.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
import org.junit.Before;
3636
import org.junit.Test;
3737

38-
import org.springframework.context.event.ContextRefreshedEvent;
39-
import org.springframework.context.support.StaticApplicationContext;
38+
import org.springframework.context.support.GenericApplicationContext;
4039
import org.springframework.core.task.TaskExecutor;
4140
import org.springframework.jms.StubQueue;
4241
import org.springframework.util.ErrorHandler;
@@ -130,7 +129,9 @@ public void testContextRefreshedEventDoesNotStartTheConnectionIfAutoStartIsSetTo
130129
this.container.setMessageListener(new TestMessageListener());
131130
this.container.setAutoStartup(false);
132131
this.container.afterPropertiesSet();
133-
this.container.onApplicationEvent(new ContextRefreshedEvent(new StaticApplicationContext()));
132+
GenericApplicationContext context = new GenericApplicationContext();
133+
context.getBeanFactory().registerSingleton("messageListenerContainer", this.container);
134+
context.refresh();
134135

135136
mockMessageConsumer.verify();
136137
mockSession.verify();
@@ -181,7 +182,9 @@ public void testContextRefreshedEventStartsTheConnectionByDefault() throws Excep
181182

182183
this.container.setMessageListener(new TestMessageListener());
183184
this.container.afterPropertiesSet();
184-
this.container.onApplicationEvent(new ContextRefreshedEvent(new StaticApplicationContext()));
185+
GenericApplicationContext context = new GenericApplicationContext();
186+
context.getBeanFactory().registerSingleton("messageListenerContainer", this.container);
187+
context.refresh();
185188

186189
mockMessageConsumer.verify();
187190
mockSession.verify();

0 commit comments

Comments
 (0)
Please sign in to comment.