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 38288acbd4..ebbf7e3c56 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 @@ -21,6 +21,7 @@ import java.time.Duration; import jakarta.jms.ConnectionFactory; import jakarta.jms.ExceptionListener; +import org.springframework.boot.autoconfigure.jms.JmsProperties.Listener.Session; import org.springframework.jms.config.DefaultJmsListenerContainerFactory; import org.springframework.jms.support.converter.MessageConverter; import org.springframework.jms.support.destination.DestinationResolver; @@ -103,14 +104,16 @@ public final class DefaultJmsListenerContainerFactoryConfigurer { factory.setConnectionFactory(connectionFactory); factory.setPubSubDomain(this.jmsProperties.isPubSubDomain()); JmsProperties.Listener listener = this.jmsProperties.getListener(); + Session session = listener.getSession(); + Boolean sessionTransacted = session.getTransacted(); if (this.transactionManager != null) { factory.setTransactionManager(this.transactionManager); } - else if (listener.getSessionTransacted() == null) { + else if (sessionTransacted == null) { factory.setSessionTransacted(true); } - if (listener.getSessionTransacted() != null) { - factory.setSessionTransacted(listener.getSessionTransacted()); + if (sessionTransacted != null) { + factory.setSessionTransacted(sessionTransacted); } if (this.destinationResolver != null) { factory.setDestinationResolver(this.destinationResolver); @@ -122,7 +125,7 @@ public final class DefaultJmsListenerContainerFactoryConfigurer { factory.setExceptionListener(this.exceptionListener); } factory.setAutoStartup(listener.isAutoStartup()); - factory.setSessionAcknowledgeMode(listener.getSession().getAcknowledgeMode().getMode()); + factory.setSessionAcknowledgeMode(session.getAcknowledgeMode().getMode()); String concurrency = listener.formatConcurrency(); if (concurrency != null) { factory.setConcurrency(concurrency); 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 46d9a70518..cc6d314069 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 @@ -141,11 +141,6 @@ public class JmsProperties { */ private boolean autoStartup = true; - /** - * Whether the container should use transacted JMS sessions. - */ - private Boolean sessionTransacted; - /** * Minimum number of concurrent consumers. When max-concurrency is not specified * the minimum will also be used as the maximum. @@ -185,14 +180,6 @@ public class JmsProperties { this.session.setAcknowledgeMode(acknowledgeMode); } - public Boolean getSessionTransacted() { - return this.sessionTransacted; - } - - public void setSessionTransacted(Boolean sessionTransacted) { - this.sessionTransacted = sessionTransacted; - } - @DeprecatedConfigurationProperty(replacement = "spring.jms.listener.min-concurrency", since = "3.2.0") @Deprecated(since = "3.2.0", forRemoval = true) public Integer getConcurrency() { @@ -247,6 +234,12 @@ public class JmsProperties { */ private AcknowledgeMode acknowledgeMode = AcknowledgeMode.AUTO; + /** + * Whether the listener container should use transacted JMS sessions. Defaults + * to false in the presence of a JtaTransactionManager and true otherwise. + */ + private Boolean transacted; + public AcknowledgeMode getAcknowledgeMode() { return this.acknowledgeMode; } @@ -255,6 +248,14 @@ public class JmsProperties { this.acknowledgeMode = acknowledgeMode; } + public Boolean getTransacted() { + return this.transacted; + } + + public void setTransacted(Boolean transacted) { + this.transacted = transacted; + } + } } 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 6283677245..49f5ddb3b2 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 @@ -144,9 +144,9 @@ class JmsAutoConfigurationTests { void testJmsListenerContainerFactoryWithCustomSettings() { this.contextRunner.withUserConfiguration(EnableJmsConfiguration.class) .withPropertyValues("spring.jms.listener.autoStartup=false", - "spring.jms.listener.session.acknowledgeMode=client", "spring.jms.listener.sessionTransacted=false", - "spring.jms.listener.minConcurrency=2", "spring.jms.listener.receiveTimeout=2s", - "spring.jms.listener.maxConcurrency=10") + "spring.jms.listener.session.acknowledgeMode=client", + "spring.jms.listener.session.transacted=false", "spring.jms.listener.minConcurrency=2", + "spring.jms.listener.receiveTimeout=2s", "spring.jms.listener.maxConcurrency=10") .run(this::testJmsListenerContainerFactoryWithCustomSettings); } @@ -185,7 +185,7 @@ class JmsAutoConfigurationTests { @Test void testDefaultContainerFactoryWithJtaTransactionManagerAndSessionTransactedEnabled() { this.contextRunner.withUserConfiguration(TestConfiguration7.class, EnableJmsConfiguration.class) - .withPropertyValues("spring.jms.listener.sessionTransacted=true") + .withPropertyValues("spring.jms.listener.session.transacted=true") .run((context) -> { DefaultMessageListenerContainer container = getContainer(context, "jmsListenerContainerFactory"); assertThat(container.isSessionTransacted()).isTrue(); @@ -216,7 +216,7 @@ class JmsAutoConfigurationTests { @Test void testDefaultContainerFactoryNoTransactionManagerAndSessionTransactedDisabled() { this.contextRunner.withUserConfiguration(EnableJmsConfiguration.class) - .withPropertyValues("spring.jms.listener.sessionTransacted=false") + .withPropertyValues("spring.jms.listener.session.transacted=false") .run((context) -> { DefaultMessageListenerContainer container = getContainer(context, "jmsListenerContainerFactory"); assertThat(container.isSessionTransacted()).isFalse();