From 443576dd29933a9cb8611b603d6e3936d386b043 Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Thu, 27 Feb 2025 15:23:04 +0100 Subject: [PATCH] Add support for auto-configuring SimpleJmsListenerContainer This commit introduces a new `spring.jms.listener.container-type` configuration property which can be used to auto-configure JMS listener support backend by `SimpleJmsListenerContainer` instead of `DefaultJmsListenerContainer`. Signed-off-by: Vedran Pavic --- ...JmsListenerContainerFactoryConfigurer.java | 129 ++++++++++++++++++ ...JmsListenerContainerFactoryConfigurer.java | 83 ++--------- .../jms/JmsAnnotationDrivenConfiguration.java | 98 +++++++------ .../boot/autoconfigure/jms/JmsProperties.java | 27 ++++ ...JmsListenerContainerFactoryConfigurer.java | 37 +++++ .../jms/JmsAutoConfigurationTests.java | 27 +++- 6 files changed, 287 insertions(+), 114 deletions(-) create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/AbstractJmsListenerContainerFactoryConfigurer.java create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/SimpleJmsListenerContainerFactoryConfigurer.java diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/AbstractJmsListenerContainerFactoryConfigurer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/AbstractJmsListenerContainerFactoryConfigurer.java new file mode 100644 index 000000000000..8ea26796ea49 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/AbstractJmsListenerContainerFactoryConfigurer.java @@ -0,0 +1,129 @@ +/* + * Copyright 2012-2025 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.jms; + +import io.micrometer.observation.ObservationRegistry; +import jakarta.jms.ConnectionFactory; +import jakarta.jms.ExceptionListener; + +import org.springframework.boot.autoconfigure.jms.JmsProperties.Listener.Session; +import org.springframework.boot.context.properties.PropertyMapper; +import org.springframework.jms.config.AbstractJmsListenerContainerFactory; +import org.springframework.jms.support.converter.MessageConverter; +import org.springframework.jms.support.destination.DestinationResolver; +import org.springframework.util.Assert; + +/** + * Configures {@link AbstractJmsListenerContainerFactory} with sensible defaults. + * + * @param the connection factory type. + * @author Vedran Pavic + * @since 3.5.0 + */ +public abstract class AbstractJmsListenerContainerFactoryConfigurer> { + + private DestinationResolver destinationResolver; + + private MessageConverter messageConverter; + + private ExceptionListener exceptionListener; + + private ObservationRegistry observationRegistry; + + private JmsProperties jmsProperties; + + /** + * Set the {@link DestinationResolver} to use or {@code null} if no destination + * resolver should be associated with the factory by default. + * @param destinationResolver the {@link DestinationResolver} + */ + void setDestinationResolver(DestinationResolver destinationResolver) { + this.destinationResolver = destinationResolver; + } + + /** + * Set the {@link MessageConverter} to use or {@code null} if the out-of-the-box + * converter should be used. + * @param messageConverter the {@link MessageConverter} + */ + void setMessageConverter(MessageConverter messageConverter) { + this.messageConverter = messageConverter; + } + + /** + * Set the {@link ExceptionListener} to use or {@code null} if no exception listener + * should be associated by default. + * @param exceptionListener the {@link ExceptionListener} + */ + void setExceptionListener(ExceptionListener exceptionListener) { + this.exceptionListener = exceptionListener; + } + + /** + * Set the {@link ObservationRegistry} to use. + * @param observationRegistry the {@link ObservationRegistry} + */ + void setObservationRegistry(ObservationRegistry observationRegistry) { + this.observationRegistry = observationRegistry; + } + + /** + * Set the {@link JmsProperties} to use. + * @param jmsProperties the {@link JmsProperties} + */ + void setJmsProperties(JmsProperties jmsProperties) { + this.jmsProperties = jmsProperties; + } + + /** + * Configure the specified jms listener container factory. The factory can be further + * tuned and default settings can be overridden. + * @param factory the {@link AbstractJmsListenerContainerFactory} instance to + * configure + * @param connectionFactory the {@link ConnectionFactory} to use + */ + public void configure(T factory, ConnectionFactory connectionFactory) { + Assert.notNull(factory, "'factory' must not be null"); + Assert.notNull(connectionFactory, "'connectionFactory' must not be null"); + JmsProperties.Listener listenerProperties = this.jmsProperties.getListener(); + Session sessionProperties = listenerProperties.getSession(); + factory.setConnectionFactory(connectionFactory); + PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); + map.from(this.jmsProperties::isPubSubDomain).to(factory::setPubSubDomain); + map.from(this.jmsProperties::isSubscriptionDurable).to(factory::setSubscriptionDurable); + map.from(this.jmsProperties::getClientId).to(factory::setClientId); + map.from(this.destinationResolver).to(factory::setDestinationResolver); + map.from(this.messageConverter).to(factory::setMessageConverter); + map.from(this.exceptionListener).to(factory::setExceptionListener); + map.from(sessionProperties.getAcknowledgeMode()::getMode).to(factory::setSessionAcknowledgeMode); + map.from(this.observationRegistry).to(factory::setObservationRegistry); + map.from(sessionProperties::getTransacted).to(factory::setSessionTransacted); + map.from(listenerProperties::isAutoStartup).to(factory::setAutoStartup); + configure(factory, connectionFactory, this.jmsProperties); + } + + /** + * Configures the given {@code factory} using the given {@code connectionFactory} and + * {@code jmsProperties}. + * @param factory the {@link AbstractJmsListenerContainerFactory} instance to + * configure + * @param connectionFactory the {@link ConnectionFactory} to use + * @param jmsProperties the {@link JmsProperties} to use + */ + protected abstract void configure(T factory, ConnectionFactory connectionFactory, JmsProperties jmsProperties); + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/DefaultJmsListenerContainerFactoryConfigurer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/DefaultJmsListenerContainerFactoryConfigurer.java index de88b4b0a368..466272685553 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/DefaultJmsListenerContainerFactoryConfigurer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/DefaultJmsListenerContainerFactoryConfigurer.java @@ -20,18 +20,14 @@ import io.micrometer.observation.ObservationRegistry; import jakarta.jms.ConnectionFactory; -import jakarta.jms.ExceptionListener; import org.springframework.boot.autoconfigure.jms.JmsProperties.Listener.Session; import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.jms.config.DefaultJmsListenerContainerFactory; -import org.springframework.jms.support.converter.MessageConverter; -import org.springframework.jms.support.destination.DestinationResolver; import org.springframework.transaction.jta.JtaTransactionManager; -import org.springframework.util.Assert; /** - * Configure {@link DefaultJmsListenerContainerFactory} with sensible defaults. + * Configures {@link DefaultJmsListenerContainerFactory} with sensible defaults. * * @author Stephane Nicoll * @author Eddú Meléndez @@ -39,47 +35,11 @@ * @author Lasse Wulff * @since 1.3.3 */ -public final class DefaultJmsListenerContainerFactoryConfigurer { - - private DestinationResolver destinationResolver; - - private MessageConverter messageConverter; - - private ExceptionListener exceptionListener; +public final class DefaultJmsListenerContainerFactoryConfigurer + extends AbstractJmsListenerContainerFactoryConfigurer { private JtaTransactionManager transactionManager; - private JmsProperties jmsProperties; - - private ObservationRegistry observationRegistry; - - /** - * Set the {@link DestinationResolver} to use or {@code null} if no destination - * resolver should be associated with the factory by default. - * @param destinationResolver the {@link DestinationResolver} - */ - void setDestinationResolver(DestinationResolver destinationResolver) { - this.destinationResolver = destinationResolver; - } - - /** - * Set the {@link MessageConverter} to use or {@code null} if the out-of-the-box - * converter should be used. - * @param messageConverter the {@link MessageConverter} - */ - void setMessageConverter(MessageConverter messageConverter) { - this.messageConverter = messageConverter; - } - - /** - * Set the {@link ExceptionListener} to use or {@code null} if no exception listener - * should be associated by default. - * @param exceptionListener the {@link ExceptionListener} - */ - void setExceptionListener(ExceptionListener exceptionListener) { - this.exceptionListener = exceptionListener; - } - /** * Set the {@link JtaTransactionManager} to use or {@code null} if the JTA support * should not be used. @@ -89,50 +49,25 @@ void setTransactionManager(JtaTransactionManager transactionManager) { this.transactionManager = transactionManager; } - /** - * Set the {@link JmsProperties} to use. - * @param jmsProperties the {@link JmsProperties} - */ - void setJmsProperties(JmsProperties jmsProperties) { - this.jmsProperties = jmsProperties; - } - /** * Set the {@link ObservationRegistry} to use. * @param observationRegistry the {@link ObservationRegistry} * @since 3.2.1 */ public void setObservationRegistry(ObservationRegistry observationRegistry) { - this.observationRegistry = observationRegistry; + super.setObservationRegistry(observationRegistry); } - /** - * Configure the specified jms listener container factory. The factory can be further - * tuned and default settings can be overridden. - * @param factory the {@link DefaultJmsListenerContainerFactory} instance to configure - * @param connectionFactory the {@link ConnectionFactory} to use - */ - public void configure(DefaultJmsListenerContainerFactory factory, ConnectionFactory connectionFactory) { - Assert.notNull(factory, "'factory' must not be null"); - Assert.notNull(connectionFactory, "'connectionFactory' must not be null"); - JmsProperties.Listener listenerProperties = this.jmsProperties.getListener(); - Session sessionProperties = listenerProperties.getSession(); - factory.setConnectionFactory(connectionFactory); + @Override + protected void configure(DefaultJmsListenerContainerFactory factory, ConnectionFactory connectionFactory, + JmsProperties jmsProperties) { PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); - map.from(this.jmsProperties::isPubSubDomain).to(factory::setPubSubDomain); - map.from(this.jmsProperties::isSubscriptionDurable).to(factory::setSubscriptionDurable); - map.from(this.jmsProperties::getClientId).to(factory::setClientId); + JmsProperties.Listener listenerProperties = jmsProperties.getListener(); + Session sessionProperties = listenerProperties.getSession(); map.from(this.transactionManager).to(factory::setTransactionManager); - map.from(this.destinationResolver).to(factory::setDestinationResolver); - map.from(this.messageConverter).to(factory::setMessageConverter); - map.from(this.exceptionListener).to(factory::setExceptionListener); - map.from(sessionProperties.getAcknowledgeMode()::getMode).to(factory::setSessionAcknowledgeMode); if (this.transactionManager == null && sessionProperties.getTransacted() == null) { factory.setSessionTransacted(true); } - map.from(this.observationRegistry).to(factory::setObservationRegistry); - map.from(sessionProperties::getTransacted).to(factory::setSessionTransacted); - map.from(listenerProperties::isAutoStartup).to(factory::setAutoStartup); map.from(listenerProperties::formatConcurrency).to(factory::setConcurrency); map.from(listenerProperties::getReceiveTimeout).as(Duration::toMillis).to(factory::setReceiveTimeout); map.from(listenerProperties::getMaxMessagesPerTask).to(factory::setMaxMessagesPerTask); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsAnnotationDrivenConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsAnnotationDrivenConfiguration.java index cea5d85401d4..12a496dcb4b8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsAnnotationDrivenConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsAnnotationDrivenConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -24,6 +24,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnJndi; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; import org.springframework.boot.jms.ConnectionFactoryUnwrapper; import org.springframework.context.annotation.Bean; @@ -31,6 +32,7 @@ import org.springframework.jms.annotation.EnableJms; import org.springframework.jms.config.DefaultJmsListenerContainerFactory; import org.springframework.jms.config.JmsListenerConfigUtils; +import org.springframework.jms.config.SimpleJmsListenerContainerFactory; import org.springframework.jms.support.converter.MessageConverter; import org.springframework.jms.support.destination.DestinationResolver; import org.springframework.jms.support.destination.JndiDestinationResolver; @@ -42,56 +44,74 @@ * @author Phillip Webb * @author Stephane Nicoll * @author Eddú Meléndez + * @author Vedran Pavic */ @Configuration(proxyBeanMethods = false) @ConditionalOnClass(EnableJms.class) class JmsAnnotationDrivenConfiguration { - private final ObjectProvider destinationResolver; - - private final ObjectProvider transactionManager; + @Configuration(proxyBeanMethods = false) + @ConditionalOnProperty(name = "spring.jms.listener.container-type", havingValue = "default", matchIfMissing = true) + static class DefaultJmsListenerContainerFactoryConfiguration { - private final ObjectProvider messageConverter; + @Bean + @ConditionalOnMissingBean + DefaultJmsListenerContainerFactoryConfigurer jmsListenerContainerFactoryConfigurer( + ObjectProvider destinationResolver, + ObjectProvider transactionManager, + ObjectProvider messageConverter, ObjectProvider exceptionListener, + ObjectProvider observationRegistry, JmsProperties properties) { + DefaultJmsListenerContainerFactoryConfigurer configurer = new DefaultJmsListenerContainerFactoryConfigurer(); + configurer.setDestinationResolver(destinationResolver.getIfUnique()); + configurer.setTransactionManager(transactionManager.getIfUnique()); + configurer.setMessageConverter(messageConverter.getIfUnique()); + configurer.setExceptionListener(exceptionListener.getIfUnique()); + configurer.setObservationRegistry(observationRegistry.getIfUnique()); + configurer.setJmsProperties(properties); + return configurer; + } - private final ObjectProvider exceptionListener; + @Bean + @ConditionalOnSingleCandidate(ConnectionFactory.class) + @ConditionalOnMissingBean(name = "jmsListenerContainerFactory") + DefaultJmsListenerContainerFactory jmsListenerContainerFactory( + DefaultJmsListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) { + DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); + configurer.configure(factory, ConnectionFactoryUnwrapper.unwrapCaching(connectionFactory)); + return factory; + } - private final ObjectProvider observationRegistry; + } - private final JmsProperties properties; + @Configuration(proxyBeanMethods = false) + @ConditionalOnProperty(name = "spring.jms.listener.container-type", havingValue = "simple") + static class SimpleJmsListenerContainerFactoryConfiguration { - JmsAnnotationDrivenConfiguration(ObjectProvider destinationResolver, - ObjectProvider transactionManager, ObjectProvider messageConverter, - ObjectProvider exceptionListener, - ObjectProvider observationRegistry, JmsProperties properties) { - this.destinationResolver = destinationResolver; - this.transactionManager = transactionManager; - this.messageConverter = messageConverter; - this.exceptionListener = exceptionListener; - this.observationRegistry = observationRegistry; - this.properties = properties; - } + @Bean + @ConditionalOnMissingBean + SimpleJmsListenerContainerFactoryConfigurer jmsListenerContainerFactoryConfigurer( + ObjectProvider destinationResolver, + ObjectProvider messageConverter, ObjectProvider exceptionListener, + ObjectProvider observationRegistry, JmsProperties properties) { + SimpleJmsListenerContainerFactoryConfigurer configurer = new SimpleJmsListenerContainerFactoryConfigurer(); + configurer.setDestinationResolver(destinationResolver.getIfUnique()); + configurer.setMessageConverter(messageConverter.getIfUnique()); + configurer.setExceptionListener(exceptionListener.getIfUnique()); + configurer.setObservationRegistry(observationRegistry.getIfUnique()); + configurer.setJmsProperties(properties); + return configurer; + } - @Bean - @ConditionalOnMissingBean - DefaultJmsListenerContainerFactoryConfigurer jmsListenerContainerFactoryConfigurer() { - DefaultJmsListenerContainerFactoryConfigurer configurer = new DefaultJmsListenerContainerFactoryConfigurer(); - configurer.setDestinationResolver(this.destinationResolver.getIfUnique()); - configurer.setTransactionManager(this.transactionManager.getIfUnique()); - configurer.setMessageConverter(this.messageConverter.getIfUnique()); - configurer.setExceptionListener(this.exceptionListener.getIfUnique()); - configurer.setObservationRegistry(this.observationRegistry.getIfUnique()); - configurer.setJmsProperties(this.properties); - return configurer; - } + @Bean + @ConditionalOnSingleCandidate(ConnectionFactory.class) + @ConditionalOnMissingBean(name = "jmsListenerContainerFactory") + SimpleJmsListenerContainerFactory jmsListenerContainerFactory( + SimpleJmsListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) { + SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory(); + configurer.configure(factory, ConnectionFactoryUnwrapper.unwrapCaching(connectionFactory)); + return factory; + } - @Bean - @ConditionalOnSingleCandidate(ConnectionFactory.class) - @ConditionalOnMissingBean(name = "jmsListenerContainerFactory") - DefaultJmsListenerContainerFactory jmsListenerContainerFactory( - DefaultJmsListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) { - DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); - configurer.configure(factory, ConnectionFactoryUnwrapper.unwrapCaching(connectionFactory)); - return factory; } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java index b64b2a258ab9..ebbab5ec3862 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java @@ -163,6 +163,11 @@ public void setSessionCacheSize(int sessionCacheSize) { public static class Listener { + /** + * Listener container type. + */ + private ContainerType containerType = ContainerType.DEFAULT; + /** * Start the container automatically on startup. */ @@ -195,6 +200,14 @@ public static class Listener { private final Session session = new Session(); + public ContainerType getContainerType() { + return this.containerType; + } + + public void setContainerType(ContainerType containerType) { + this.containerType = containerType; + } + public boolean isAutoStartup() { return this.autoStartup; } @@ -445,6 +458,20 @@ public void setTransacted(boolean transacted) { } + public enum ContainerType { + + /** + * Use DefaultMessageListenerContainer. + */ + DEFAULT, + + /** + * Use SimpleMessageListenerContainer. + */ + SIMPLE + + } + public enum DeliveryMode { /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/SimpleJmsListenerContainerFactoryConfigurer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/SimpleJmsListenerContainerFactoryConfigurer.java new file mode 100644 index 000000000000..b92e6398cb0d --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/SimpleJmsListenerContainerFactoryConfigurer.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012-2025 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.jms; + +import jakarta.jms.ConnectionFactory; + +import org.springframework.jms.config.SimpleJmsListenerContainerFactory; + +/** + * Configures {@link SimpleJmsListenerContainerFactory} with sensible defaults. + * + * @author Vedran Pavic + * @since 3.5.0 + */ +public final class SimpleJmsListenerContainerFactoryConfigurer + extends AbstractJmsListenerContainerFactoryConfigurer { + + @Override + protected void configure(SimpleJmsListenerContainerFactory factory, ConnectionFactory connectionFactory, + JmsProperties jmsProperties) { + } + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java index 7df4a2ad49c7..c11e5791d1c4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -49,6 +49,7 @@ import org.springframework.jms.core.JmsMessagingTemplate; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.listener.DefaultMessageListenerContainer; +import org.springframework.jms.listener.SimpleMessageListenerContainer; import org.springframework.jms.support.converter.MessageConverter; import org.springframework.jms.support.destination.DestinationResolver; import org.springframework.transaction.jta.JtaTransactionManager; @@ -147,6 +148,30 @@ void testDefaultJmsListenerConfiguration() { }); } + @Test + void testSimpleJmsListenerConfiguration() { + this.contextRunner.withUserConfiguration(TestConfiguration.class) + .withPropertyValues("spring.jms.listener.container-type=simple") + .run((loaded) -> { + assertThat(loaded).hasSingleBean(CachingConnectionFactory.class); + CachingConnectionFactory connectionFactory = loaded.getBean(CachingConnectionFactory.class); + assertThat(loaded).hasSingleBean(SimpleJmsListenerContainerFactory.class); + SimpleJmsListenerContainerFactory containerFactory = loaded + .getBean(SimpleJmsListenerContainerFactory.class); + SimpleJmsListenerEndpoint jmsListenerEndpoint = new SimpleJmsListenerEndpoint(); + jmsListenerEndpoint.setMessageListener((message) -> { + }); + SimpleMessageListenerContainer container = containerFactory + .createListenerContainer(jmsListenerEndpoint); + assertThat(container.getClientId()).isNull(); + assertThat(container.getConnectionFactory()).isSameAs(connectionFactory.getTargetConnectionFactory()); + assertThat(container.getSessionAcknowledgeMode()).isEqualTo(Session.AUTO_ACKNOWLEDGE); + assertThat(container.isAutoStartup()).isTrue(); + assertThat(container.isPubSubDomain()).isFalse(); + assertThat(container.isSubscriptionDurable()).isFalse(); + }); + } + @Test void testEnableJmsCreateDefaultContainerFactory() { this.contextRunner.withUserConfiguration(EnableJmsConfiguration.class)