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
master
Stephane Nicoll 10 years ago
parent b6449baaa6
commit 6f3570a0f6
  1. 13
      spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerContainerFactory.java
  2. 2
      spring-jms/src/test/java/org/springframework/jms/config/JmsListenerContainerFactoryTests.java

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -60,6 +60,8 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess
private Integer phase;
private Boolean autoStartup;
/**
* @see AbstractMessageListenerContainer#setConnectionFactory(ConnectionFactory)
@ -138,6 +140,12 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess
this.phase = phase;
}
/**
* @see AbstractMessageListenerContainer#setAutoStartup(boolean)
*/
public void setAutoStartup(boolean autoStartup) {
this.autoStartup = autoStartup;
}
@Override
public C createListenerContainer(JmsListenerEndpoint endpoint) {
@ -176,6 +184,9 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess
if (this.phase != null) {
instance.setPhase(this.phase);
}
if (this.autoStartup != null) {
instance.setAutoStartup(this.autoStartup);
}
endpoint.setupListenerContainer(instance);
initializeContainer(instance);

@ -157,6 +157,7 @@ public class JmsListenerContainerFactoryTests {
factory.setPubSubDomain(true);
factory.setSubscriptionDurable(true);
factory.setClientId("client-1234");
factory.setAutoStartup(false);
}
private void assertDefaultJmsConfig(AbstractMessageListenerContainer container) {
@ -168,6 +169,7 @@ public class JmsListenerContainerFactoryTests {
assertEquals(true, container.isPubSubDomain());
assertEquals(true, container.isSubscriptionDurable());
assertEquals("client-1234", container.getClientId());
assertEquals(false, container.isAutoStartup());
}
private void setDefaultJcaConfig(DefaultJcaListenerContainerFactory factory) {

Loading…
Cancel
Save