Skip to content

Commit 6f3570a

Browse files
committed
Add auto-startup support for JmsListenerContainerFactory
The auto startup flag can now be set on a JmsListenerContainerFactory to control if the created container should be started automatically when the application context starts. Issue: SPR-12824
1 parent b6449ba commit 6f3570a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerContainerFactory.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,6 +60,8 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess
6060

6161
private Integer phase;
6262

63+
private Boolean autoStartup;
64+
6365

6466
/**
6567
* @see AbstractMessageListenerContainer#setConnectionFactory(ConnectionFactory)
@@ -138,6 +140,12 @@ public void setPhase(int phase) {
138140
this.phase = phase;
139141
}
140142

143+
/**
144+
* @see AbstractMessageListenerContainer#setAutoStartup(boolean)
145+
*/
146+
public void setAutoStartup(boolean autoStartup) {
147+
this.autoStartup = autoStartup;
148+
}
141149

142150
@Override
143151
public C createListenerContainer(JmsListenerEndpoint endpoint) {
@@ -176,6 +184,9 @@ public C createListenerContainer(JmsListenerEndpoint endpoint) {
176184
if (this.phase != null) {
177185
instance.setPhase(this.phase);
178186
}
187+
if (this.autoStartup != null) {
188+
instance.setAutoStartup(this.autoStartup);
189+
}
179190

180191
endpoint.setupListenerContainer(instance);
181192
initializeContainer(instance);

spring-jms/src/test/java/org/springframework/jms/config/JmsListenerContainerFactoryTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ private void setDefaultJmsConfig(AbstractJmsListenerContainerFactory<?> factory)
157157
factory.setPubSubDomain(true);
158158
factory.setSubscriptionDurable(true);
159159
factory.setClientId("client-1234");
160+
factory.setAutoStartup(false);
160161
}
161162

162163
private void assertDefaultJmsConfig(AbstractMessageListenerContainer container) {
@@ -168,6 +169,7 @@ private void assertDefaultJmsConfig(AbstractMessageListenerContainer container)
168169
assertEquals(true, container.isPubSubDomain());
169170
assertEquals(true, container.isSubscriptionDurable());
170171
assertEquals("client-1234", container.getClientId());
172+
assertEquals(false, container.isAutoStartup());
171173
}
172174

173175
private void setDefaultJcaConfig(DefaultJcaListenerContainerFactory factory) {

0 commit comments

Comments
 (0)