diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfiguration.java index 21f6fd95a7..4add88c74b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfiguration.java @@ -89,10 +89,9 @@ public class JmsAutoConfiguration { private void mapTemplateProperties(Template properties, JmsTemplate template) { PropertyMapper map = PropertyMapper.get(); - map.from(properties::getAcknowledgeMode) - .whenNonNull() + map.from(properties.getSession()::getAcknowledgeMode) .to((acknowledgeMode) -> template.setSessionAcknowledgeMode(acknowledgeMode.getMode())); - map.from(properties::getSessionTransacted).whenNonNull().to(template::setSessionTransacted); + map.from(properties.getSession()::isTransacted).to(template::setSessionTransacted); map.from(properties::getDefaultDestination).whenNonNull().to(template::setDefaultDestinationName); map.from(properties::getDeliveryDelay).whenNonNull().as(Duration::toMillis).to(template::setDeliveryDelay); map.from(properties::determineQosEnabled).to(template::setExplicitQosEnabled); 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 b5b4ec7d2e..a8a2ed034a 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 @@ -228,16 +228,6 @@ public class JmsProperties { public static class Template { - /** - * Acknowledgement mode used when creating JMS sessions to send a message. - */ - private AcknowledgeMode acknowledgeMode; - - /** - * Whether to use transacted JMS sessions. - */ - private Boolean sessionTransacted; - /** * Default destination to use on send and receive operations that do not have a * destination parameter. @@ -278,21 +268,7 @@ public class JmsProperties { */ private Duration receiveTimeout; - public AcknowledgeMode getAcknowledgeMode() { - return this.acknowledgeMode; - } - - public void setAcknowledgeMode(AcknowledgeMode acknowledgeMode) { - this.acknowledgeMode = acknowledgeMode; - } - - public Boolean getSessionTransacted() { - return this.sessionTransacted; - } - - public void setSessionTransacted(Boolean sessionTransacted) { - this.sessionTransacted = sessionTransacted; - } + private final Session session = new Session(); public String getDefaultDestination() { return this.defaultDestination; @@ -357,6 +333,40 @@ public class JmsProperties { this.receiveTimeout = receiveTimeout; } + public Session getSession() { + return this.session; + } + + public static class Session { + + /** + * Acknowledge mode used when creating sessions. + */ + private AcknowledgeMode acknowledgeMode = AcknowledgeMode.AUTO; + + /** + * Whether to use transacted sessions. + */ + private boolean transacted = false; + + public AcknowledgeMode getAcknowledgeMode() { + return this.acknowledgeMode; + } + + public void setAcknowledgeMode(AcknowledgeMode acknowledgeMode) { + this.acknowledgeMode = acknowledgeMode; + } + + public boolean isTransacted() { + return this.transacted; + } + + public void setTransacted(boolean transacted) { + this.transacted = transacted; + } + + } + } /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index db3b6221d0..fd6e0a9aa5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -1571,6 +1571,10 @@ "name": "spring.jersey.type", "defaultValue": "servlet" }, + { + "name": "spring.jms.template.session.acknowledge-mode", + "defaultValue": "auto" + }, { "name": "spring.jpa.hibernate.use-new-id-generator-mappings", "type": "java.lang.Boolean", 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 69071f2f13..a03845da1b 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 @@ -253,8 +253,8 @@ class JmsAutoConfigurationTests { @Test void testJmsTemplateFullCustomization() { this.contextRunner.withUserConfiguration(MessageConvertersConfiguration.class) - .withPropertyValues("spring.jms.template.acknowledge-mode=client", - "spring.jms.template.session-transacted=true", "spring.jms.template.default-destination=testQueue", + .withPropertyValues("spring.jms.template.session.acknowledge-mode=client", + "spring.jms.template.session.transacted=true", "spring.jms.template.default-destination=testQueue", "spring.jms.template.delivery-delay=500", "spring.jms.template.delivery-mode=non-persistent", "spring.jms.template.priority=6", "spring.jms.template.time-to-live=6000", "spring.jms.template.receive-timeout=2000")