Apply pubSubDomain property to ContainerFactory

Previously, tuning the pubSubDomain flag only impacted the created
JmsTemplate leaving any default listeners with the default settings.

If no default JmsListenerContainerFactory is defined, the created
one is using that property as well now.
This commit is contained in:
Maciej Walkowiak 2014-12-01 13:38:18 +01:00 committed by Stephane Nicoll
parent 4ce621951c
commit c74e56d185
2 changed files with 18 additions and 0 deletions

View File

@ -48,12 +48,16 @@ class JmsAnnotationDrivenConfiguration {
@Autowired(required = false)
private PlatformTransactionManager transactionManager;
@Autowired
private JmsProperties properties;
@Bean
@ConditionalOnMissingBean(name = "jmsListenerContainerFactory")
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(
ConnectionFactory connectionFactory) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setPubSubDomain(properties.isPubSubDomain());
if (this.transactionManager != null) {
factory.setTransactionManager(this.transactionManager);
}

View File

@ -34,13 +34,16 @@ import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerConfigUtils;
import org.springframework.jms.config.JmsListenerContainerFactory;
import org.springframework.jms.config.SimpleJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerEndpoint;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link JmsAutoConfiguration}.
@ -148,6 +151,17 @@ public class JmsAutoConfigurationTests {
assertTrue(jmsTemplate.isPubSubDomain());
}
@Test
public void testPubSubDomainActive() {
load(TestConfiguration.class, "spring.jms.pubSubDomain:true");
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
DefaultMessageListenerContainer defaultMessageListenerContainer = this.context
.getBean(DefaultJmsListenerContainerFactory.class)
.createListenerContainer(mock(JmsListenerEndpoint.class));
assertTrue(jmsTemplate.isPubSubDomain());
assertTrue(defaultMessageListenerContainer.isPubSubDomain());
}
@Test
public void testPubSubDomainOverride() {
load(TestConfiguration.class, "spring.jms.pubSubDomain:false");