diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitStreamConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitStreamConfiguration.java index acbddb51797..923e602cd12 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitStreamConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitStreamConfiguration.java @@ -47,11 +47,11 @@ import org.springframework.rabbit.stream.support.converter.StreamMessageConverte */ @Configuration(proxyBeanMethods = false) @ConditionalOnClass(StreamRabbitListenerContainerFactory.class) -@ConditionalOnProperty(prefix = "spring.rabbitmq.listener", name = "type", havingValue = "stream") class RabbitStreamConfiguration { @Bean(name = "rabbitListenerContainerFactory") @ConditionalOnMissingBean(name = "rabbitListenerContainerFactory") + @ConditionalOnProperty(prefix = "spring.rabbitmq.listener", name = "type", havingValue = "stream") StreamRabbitListenerContainerFactory streamRabbitListenerContainerFactory(Environment rabbitStreamEnvironment, RabbitProperties properties, ObjectProvider consumerCustomizer, ObjectProvider> containerCustomizer) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitStreamConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitStreamConfigurationTests.java index 6b9f6c9f31b..28ded16b43b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitStreamConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitStreamConfigurationTests.java @@ -80,6 +80,11 @@ class RabbitStreamConfigurationTests { .extracting("nativeListener", InstanceOfAssertFactories.BOOLEAN).isTrue()); } + @Test + void environmentIsAutoConfiguredByDefault() { + this.contextRunner.run((context) -> assertThat(context).hasSingleBean(Environment.class)); + } + @Test void whenCustomEnvironmentIsDefinedThenAutoConfiguredEnvironmentBacksOff() { this.contextRunner.withUserConfiguration(CustomEnvironmentConfiguration.class).run((context) -> { @@ -156,13 +161,11 @@ class RabbitStreamConfigurationTests { @Test void testDefaultRabbitStreamTemplateConfiguration() { - this.contextRunner - .withPropertyValues("spring.rabbitmq.listener.type:stream", "spring.rabbitmq.stream.name:stream-test") - .run((context) -> { - assertThat(context).hasSingleBean(RabbitStreamTemplate.class); - assertThat(context.getBean(RabbitStreamTemplate.class)).hasFieldOrPropertyWithValue("streamName", - "stream-test"); - }); + this.contextRunner.withPropertyValues("spring.rabbitmq.stream.name:stream-test").run((context) -> { + assertThat(context).hasSingleBean(RabbitStreamTemplate.class); + assertThat(context.getBean(RabbitStreamTemplate.class)).hasFieldOrPropertyWithValue("streamName", + "stream-test"); + }); } @Test @@ -174,8 +177,7 @@ class RabbitStreamConfigurationTests { @Test void testRabbitStreamTemplateConfigurationWithCustomMessageConverter() { this.contextRunner.withUserConfiguration(MessageConvertersConfiguration.class) - .withPropertyValues("spring.rabbitmq.listener.type:stream", "spring.rabbitmq.stream.name:stream-test") - .run((context) -> { + .withPropertyValues("spring.rabbitmq.stream.name:stream-test").run((context) -> { assertThat(context).hasSingleBean(RabbitStreamTemplate.class); RabbitStreamTemplate streamTemplate = context.getBean(RabbitStreamTemplate.class); assertThat(streamTemplate).hasFieldOrPropertyWithValue("streamName", "stream-test"); @@ -189,8 +191,7 @@ class RabbitStreamConfigurationTests { this.contextRunner .withBean("myStreamMessageConverter", StreamMessageConverter.class, () -> mock(StreamMessageConverter.class)) - .withPropertyValues("spring.rabbitmq.listener.type:stream", "spring.rabbitmq.stream.name:stream-test") - .run((context) -> { + .withPropertyValues("spring.rabbitmq.stream.name:stream-test").run((context) -> { assertThat(context).hasSingleBean(RabbitStreamTemplate.class); assertThat(context.getBean(RabbitStreamTemplate.class)).extracting("messageConverter") .isSameAs(context.getBean("myStreamMessageConverter")); @@ -201,8 +202,7 @@ class RabbitStreamConfigurationTests { void testRabbitStreamTemplateConfigurationWithCustomProducerCustomizer() { this.contextRunner .withBean("myProducerCustomizer", ProducerCustomizer.class, () -> mock(ProducerCustomizer.class)) - .withPropertyValues("spring.rabbitmq.listener.type:stream", "spring.rabbitmq.stream.name:stream-test") - .run((context) -> { + .withPropertyValues("spring.rabbitmq.stream.name:stream-test").run((context) -> { assertThat(context).hasSingleBean(RabbitStreamTemplate.class); assertThat(context.getBean(RabbitStreamTemplate.class)).extracting("producerCustomizer") .isSameAs(context.getBean("myProducerCustomizer"));