diff --git a/module/spring-boot-amqp-rabbitmq/src/main/java/org/springframework/boot/amqp/rabbitmq/autoconfigure/AmqpRabbitProperties.java b/module/spring-boot-amqp-rabbitmq/src/main/java/org/springframework/boot/amqp/rabbitmq/autoconfigure/AmqpRabbitProperties.java index 87825694ea66..0b0cc479deec 100644 --- a/module/spring-boot-amqp-rabbitmq/src/main/java/org/springframework/boot/amqp/rabbitmq/autoconfigure/AmqpRabbitProperties.java +++ b/module/spring-boot-amqp-rabbitmq/src/main/java/org/springframework/boot/amqp/rabbitmq/autoconfigure/AmqpRabbitProperties.java @@ -295,12 +295,12 @@ public static class Template { /** * Name of the default exchange to use for send operations. */ - private String exchange = ""; + private @Nullable String exchange; /** * Value of a default routing key to use for send operations. */ - private String routingKey = ""; + private @Nullable String routingKey; /** * Name of the default queue to receive messages from when none is specified @@ -308,19 +308,19 @@ public static class Template { */ private @Nullable String defaultReceiveQueue; - public String getExchange() { + public @Nullable String getExchange() { return this.exchange; } - public void setExchange(String exchange) { + public void setExchange(@Nullable String exchange) { this.exchange = exchange; } - public String getRoutingKey() { + public @Nullable String getRoutingKey() { return this.routingKey; } - public void setRoutingKey(String routingKey) { + public void setRoutingKey(@Nullable String routingKey) { this.routingKey = routingKey; } diff --git a/module/spring-boot-amqp-rabbitmq/src/test/java/org/springframework/boot/amqp/rabbitmq/autoconfigure/AmqpRabbitAutoConfigurationTests.java b/module/spring-boot-amqp-rabbitmq/src/test/java/org/springframework/boot/amqp/rabbitmq/autoconfigure/AmqpRabbitAutoConfigurationTests.java index 865a3e71c343..7146ba677427 100644 --- a/module/spring-boot-amqp-rabbitmq/src/test/java/org/springframework/boot/amqp/rabbitmq/autoconfigure/AmqpRabbitAutoConfigurationTests.java +++ b/module/spring-boot-amqp-rabbitmq/src/test/java/org/springframework/boot/amqp/rabbitmq/autoconfigure/AmqpRabbitAutoConfigurationTests.java @@ -219,6 +219,18 @@ void autoConfigurationConfiguresRabbitAmqpTemplateWithTemplateProperties() { }); } + @Test + void autoConfigurationDoesNotConfigureRabbitAmqpTemplateExchangeAndRoutingKeyByDefault() { + this.contextRunner + .withBean(RabbitAmqpTemplateCustomizer.class, () -> (template) -> template.setQueue("test.queue")) + .run((context) -> { + RabbitAmqpTemplate template = context.getBean(RabbitAmqpTemplate.class); + assertThat(template).hasFieldOrPropertyWithValue("defaultQueue", "test.queue"); + assertThat(template).hasFieldOrPropertyWithValue("defaultExchange", null); + assertThat(template).hasFieldOrPropertyWithValue("defaultRoutingKey", null); + }); + } + @Configuration(proxyBeanMethods = false) static class MultipleRabbitAmqpTemplateCustomizersConfiguration {