mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-28 04:59:10 +00:00
Exclude ReactorAutoConfiguration from lazy initialization
Closes gh-45846
This commit is contained in:
+7
@@ -18,10 +18,12 @@ package org.springframework.boot.autoconfigure.reactor;
|
||||
|
||||
import reactor.core.publisher.Hooks;
|
||||
|
||||
import org.springframework.boot.LazyInitializationExcludeFilter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for Reactor.
|
||||
@@ -40,4 +42,9 @@ public class ReactorAutoConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
static LazyInitializationExcludeFilter reactorAutoConfigurationLazyInitializationExcludeFilter() {
|
||||
return LazyInitializationExcludeFilter.forBeanTypes(ReactorAutoConfiguration.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+21
-7
@@ -28,6 +28,7 @@ import reactor.core.publisher.Hooks;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.context.Context;
|
||||
|
||||
import org.springframework.boot.LazyInitializationBeanFactoryPostProcessor;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
|
||||
@@ -81,13 +82,26 @@ class ReactorAutoConfigurationTests {
|
||||
@Test
|
||||
void shouldConfigurePropagationIfSetToAuto() {
|
||||
AtomicReference<String> threadLocalValue = new AtomicReference<>();
|
||||
this.contextRunner.withPropertyValues("spring.reactor.context-propagation=auto").run((applicationContext) -> {
|
||||
Mono.just("test")
|
||||
.doOnNext((element) -> threadLocalValue.set(THREADLOCAL_VALUE.get()))
|
||||
.contextWrite(Context.of(THREADLOCAL_KEY, "updated"))
|
||||
.block();
|
||||
assertThat(threadLocalValue.get()).isEqualTo("updated");
|
||||
});
|
||||
this.contextRunner.withPropertyValues("spring.reactor.context-propagation=auto")
|
||||
.run((applicationContext) -> assertThatPropagationIsWorking(threadLocalValue));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldConfigurePropagationIfSetToAutoAndLazyInitializationIsEnabled() {
|
||||
AtomicReference<String> threadLocalValue = new AtomicReference<>();
|
||||
this.contextRunner
|
||||
.withInitializer(
|
||||
(context) -> context.addBeanFactoryPostProcessor(new LazyInitializationBeanFactoryPostProcessor()))
|
||||
.withPropertyValues("spring.reactor.context-propagation=auto")
|
||||
.run((context) -> assertThatPropagationIsWorking(threadLocalValue));
|
||||
}
|
||||
|
||||
private void assertThatPropagationIsWorking(AtomicReference<String> threadLocalValue) {
|
||||
Mono.just("test")
|
||||
.doOnNext((element) -> threadLocalValue.set(THREADLOCAL_VALUE.get()))
|
||||
.contextWrite(Context.of(THREADLOCAL_KEY, "updated"))
|
||||
.block();
|
||||
assertThat(threadLocalValue.get()).isEqualTo("updated");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user