diff --git a/module/spring-boot-security/src/main/java/org/springframework/boot/security/reactive/ApplicationContextServerWebExchangeMatcher.java b/module/spring-boot-security/src/main/java/org/springframework/boot/security/reactive/ApplicationContextServerWebExchangeMatcher.java index 18afd24ac93..393641e51c1 100644 --- a/module/spring-boot-security/src/main/java/org/springframework/boot/security/reactive/ApplicationContextServerWebExchangeMatcher.java +++ b/module/spring-boot-security/src/main/java/org/springframework/boot/security/reactive/ApplicationContextServerWebExchangeMatcher.java @@ -80,16 +80,18 @@ public abstract class ApplicationContextServerWebExchangeMatcher implements S } protected Supplier getContext(ServerWebExchange exchange) { - if (this.context == null) { + Supplier context = this.context; + if (context == null) { synchronized (this.contextLock) { - if (this.context == null) { - Supplier createdContext = createContext(exchange); - initialized(createdContext); - this.context = createdContext; + context = this.context; + if (context == null) { + context = createContext(exchange); + initialized(context); + this.context = context; } } } - return this.context; + return context; } /**