From c1125d4bd58c16ee154607fdcf938f5a1dd5bbc7 Mon Sep 17 00:00:00 2001 From: LumanSuen Date: Mon, 10 Nov 2025 20:04:52 +1300 Subject: [PATCH] Fix WebSecurityCustomizer beans are excluded by WebMvcTest. See gh-47255 Signed-off-by: LumanSuen --- .../boot/webmvc/test/autoconfigure/WebMvcTest.java | 1 + .../webmvc/test/autoconfigure/WebMvcTypeExcludeFilter.java | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/WebMvcTest.java b/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/WebMvcTest.java index fbecca3c08b1..0565c446e36e 100644 --- a/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/WebMvcTest.java +++ b/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/WebMvcTest.java @@ -69,6 +69,7 @@ *
  • {@code WebMvcConfigurer}
  • *
  • {@code WebMvcRegistrations}
  • *
  • {@code WebSecurityConfigurer}
  • + *
  • {@code WebSecurityCustomizer}
  • * *

    * By default, tests annotated with {@code @WebMvcTest} will also auto-configure Spring diff --git a/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/WebMvcTypeExcludeFilter.java b/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/WebMvcTypeExcludeFilter.java index dd22845896d6..186334c409d5 100644 --- a/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/WebMvcTypeExcludeFilter.java +++ b/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/WebMvcTypeExcludeFilter.java @@ -44,6 +44,7 @@ * @author Phillip Webb * @author Madhura Bhave * @author Yanming Zhou + * @author Luman Suen */ class WebMvcTypeExcludeFilter extends StandardAnnotationCustomizableTypeExcludeFilter { @@ -52,7 +53,9 @@ class WebMvcTypeExcludeFilter extends StandardAnnotationCustomizableTypeExcludeF private static final String[] OPTIONAL_INCLUDES = { "tools.jackson.databind.JacksonModule", "org.springframework.boot.jackson.JacksonComponent", "org.springframework.security.config.annotation.web.WebSecurityConfigurer", - "org.springframework.security.web.SecurityFilterChain", "org.thymeleaf.dialect.IDialect", + "org.springframework.security.web.SecurityFilterChain", + "org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer", + "org.thymeleaf.dialect.IDialect", "com.fasterxml.jackson.databind.Module", "org.springframework.boot.jackson2.JsonComponent" }; private static final Set> KNOWN_INCLUDES;