From 1c404767c485c06bbc52d8b83b065ddb5dcdc39f Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 23 Jun 2025 20:31:24 +0100 Subject: [PATCH] Make Servlet-specific customization back off without undertow-servlet Closes gh-46178 --- ...bServerFactoryCustomizerAutoConfiguration.java | 15 +++++++++++---- ...ServerFactoryCustomizerConfigurationTests.java | 9 +++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/EmbeddedWebServerFactoryCustomizerAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/EmbeddedWebServerFactoryCustomizerAutoConfiguration.java index 00e73ab6fba..2655d2b17f4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/EmbeddedWebServerFactoryCustomizerAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/EmbeddedWebServerFactoryCustomizerAutoConfiguration.java @@ -17,6 +17,7 @@ package org.springframework.boot.autoconfigure.web.embedded; import io.undertow.Undertow; +import io.undertow.servlet.api.DeploymentInfo; import org.apache.catalina.startup.Tomcat; import org.apache.coyote.UpgradeProtocol; import org.eclipse.jetty.ee10.webapp.WebAppContext; @@ -110,10 +111,16 @@ public class EmbeddedWebServerFactoryCustomizerAutoConfiguration { return new UndertowWebServerFactoryCustomizer(environment, serverProperties); } - @Bean - @ConditionalOnThreading(Threading.VIRTUAL) - UndertowDeploymentInfoCustomizer virtualThreadsUndertowDeploymentInfoCustomizer() { - return (deploymentInfo) -> deploymentInfo.setExecutor(new VirtualThreadTaskExecutor("undertow-")); + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass(DeploymentInfo.class) + static class UndertowServletWebServerFactoryCustomizerConfiguration { + + @Bean + @ConditionalOnThreading(Threading.VIRTUAL) + UndertowDeploymentInfoCustomizer virtualThreadsUndertowDeploymentInfoCustomizer() { + return (deploymentInfo) -> deploymentInfo.setExecutor(new VirtualThreadTaskExecutor("undertow-")); + } + } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizerConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizerConfigurationTests.java index 243ea1561fc..7e03dafd681 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizerConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizerConfigurationTests.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.condition.JRE; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration.UndertowWebServerFactoryCustomizerConfiguration; +import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; import org.springframework.boot.web.embedded.undertow.UndertowDeploymentInfoCustomizer; import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext; @@ -54,4 +55,12 @@ class UndertowWebServerFactoryCustomizerConfigurationTests { }); } + @Test + @EnabledForJreRange(min = JRE.JAVA_21) + void virtualThreadCustomizationBacksOffWithoutUndertowServlet() { + this.contextRunner.withPropertyValues("spring.threads.virtual.enabled=true") + .withClassLoader(new FilteredClassLoader("io.undertow.servlet")) + .run((context) -> assertThat(context).doesNotHaveBean(UndertowDeploymentInfoCustomizer.class)); + } + }