提交 6f3570a0 编写于 作者: S Stephane Nicoll

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
上级 b6449baa
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 ...@@ -60,6 +60,8 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess
private Integer phase; private Integer phase;
private Boolean autoStartup;
/** /**
* @see AbstractMessageListenerContainer#setConnectionFactory(ConnectionFactory) * @see AbstractMessageListenerContainer#setConnectionFactory(ConnectionFactory)
...@@ -138,6 +140,12 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess ...@@ -138,6 +140,12 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess
this.phase = phase; this.phase = phase;
} }
/**
* @see AbstractMessageListenerContainer#setAutoStartup(boolean)
*/
public void setAutoStartup(boolean autoStartup) {
this.autoStartup = autoStartup;
}
@Override @Override
public C createListenerContainer(JmsListenerEndpoint endpoint) { public C createListenerContainer(JmsListenerEndpoint endpoint) {
...@@ -176,6 +184,9 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess ...@@ -176,6 +184,9 @@ public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMess
if (this.phase != null) { if (this.phase != null) {
instance.setPhase(this.phase); instance.setPhase(this.phase);
} }
if (this.autoStartup != null) {
instance.setAutoStartup(this.autoStartup);
}
endpoint.setupListenerContainer(instance); endpoint.setupListenerContainer(instance);
initializeContainer(instance); initializeContainer(instance);
......
...@@ -157,6 +157,7 @@ public class JmsListenerContainerFactoryTests { ...@@ -157,6 +157,7 @@ public class JmsListenerContainerFactoryTests {
factory.setPubSubDomain(true); factory.setPubSubDomain(true);
factory.setSubscriptionDurable(true); factory.setSubscriptionDurable(true);
factory.setClientId("client-1234"); factory.setClientId("client-1234");
factory.setAutoStartup(false);
} }
private void assertDefaultJmsConfig(AbstractMessageListenerContainer container) { private void assertDefaultJmsConfig(AbstractMessageListenerContainer container) {
...@@ -168,6 +169,7 @@ public class JmsListenerContainerFactoryTests { ...@@ -168,6 +169,7 @@ public class JmsListenerContainerFactoryTests {
assertEquals(true, container.isPubSubDomain()); assertEquals(true, container.isPubSubDomain());
assertEquals(true, container.isSubscriptionDurable()); assertEquals(true, container.isSubscriptionDurable());
assertEquals("client-1234", container.getClientId()); assertEquals("client-1234", container.getClientId());
assertEquals(false, container.isAutoStartup());
} }
private void setDefaultJcaConfig(DefaultJcaListenerContainerFactory factory) { private void setDefaultJcaConfig(DefaultJcaListenerContainerFactory factory) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册