From 6bf5e0c1d75e9f750e0265d834dee8fab0a2ee0b Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 29 Apr 2025 11:24:54 +0100 Subject: [PATCH] Create spring-boot-websocket module --- settings.gradle | 1 + ...ot.autoconfigure.AutoConfiguration.imports | 1 - .../spring-boot-dependencies/build.gradle | 3 ++- .../spring-boot-docs/build.gradle | 1 + .../build.gradle | 3 +-- .../spring-boot-websocket/build.gradle | 25 +++++++++++++++++++ .../WebSocketMessagingAutoConfiguration.java | 4 +-- .../autoconfigure}/servlet/package-info.java | 4 +-- ...ot.autoconfigure.AutoConfiguration.imports | 1 + ...SocketMessagingAutoConfigurationTests.java | 6 ++--- 10 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 spring-boot-project/spring-boot-websocket/build.gradle rename spring-boot-project/{spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/websocket => spring-boot-websocket/src/main/java/org/springframework/boot/websocket/autoconfigure}/servlet/WebSocketMessagingAutoConfiguration.java (98%) rename spring-boot-project/{spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/websocket => spring-boot-websocket/src/main/java/org/springframework/boot/websocket/autoconfigure}/servlet/package-info.java (84%) create mode 100644 spring-boot-project/spring-boot-websocket/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports rename spring-boot-project/{spring-boot-autoconfigure-all/src/test/java/org/springframework/boot/autoconfigure/websocket => spring-boot-websocket/src/test/java/org/springframework/boot/websocket/autoconfigure}/servlet/WebSocketMessagingAutoConfigurationTests.java (97%) diff --git a/settings.gradle b/settings.gradle index 8abe8d879b..7351afd18f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -145,6 +145,7 @@ include "spring-boot-project:spring-boot-validation" include "spring-boot-project:spring-boot-webflux" include "spring-boot-project:spring-boot-webmvc" include "spring-boot-project:spring-boot-webservices" +include "spring-boot-project:spring-boot-websocket" include "spring-boot-system-tests:spring-boot-deployment-tests" include "spring-boot-system-tests:spring-boot-image-tests" include "spring-boot-tests:spring-boot-integration-tests:spring-boot-configuration-processor-tests" diff --git a/spring-boot-project/spring-boot-autoconfigure-all/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-project/spring-boot-autoconfigure-all/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 7b41c7d7a6..b7a733f8cc 100644 --- a/spring-boot-project/spring-boot-autoconfigure-all/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/spring-boot-project/spring-boot-autoconfigure-all/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -9,4 +9,3 @@ org.springframework.boot.autoconfigure.web.reactive.function.client.ClientHttpCo org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientAutoConfiguration org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration -org.springframework.boot.autoconfigure.websocket.servlet.WebSocketMessagingAutoConfiguration diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index f8d6730cd7..99f2dc1fc1 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -2115,7 +2115,8 @@ bom { "spring-boot-undertow", "spring-boot-validation", "spring-boot-webflux", - "spring-boot-webmvc" + "spring-boot-webmvc", + "spring-boot-websocket" ] plugins = [ "spring-boot-maven-plugin" diff --git a/spring-boot-project/spring-boot-docs/build.gradle b/spring-boot-project/spring-boot-docs/build.gradle index 5cf28774d5..3c66cfa7c5 100644 --- a/spring-boot-project/spring-boot-docs/build.gradle +++ b/spring-boot-project/spring-boot-docs/build.gradle @@ -135,6 +135,7 @@ dependencies { autoConfiguration(project(path: ":spring-boot-project:spring-boot-webflux", configuration: "autoConfigurationMetadata")) autoConfiguration(project(path: ":spring-boot-project:spring-boot-webmvc", configuration: "autoConfigurationMetadata")) autoConfiguration(project(path: ":spring-boot-project:spring-boot-webservices", configuration: "autoConfigurationMetadata")) + autoConfiguration(project(path: ":spring-boot-project:spring-boot-websocket", configuration: "autoConfigurationMetadata")) configurationProperties(project(path: ":spring-boot-project:spring-boot", configuration: "configurationPropertiesMetadata")) configurationProperties(project(path: ":spring-boot-project:spring-boot-activemq", configuration: "configurationPropertiesMetadata")) diff --git a/spring-boot-project/spring-boot-starters/spring-boot-starter-websocket/build.gradle b/spring-boot-project/spring-boot-starters/spring-boot-starter-websocket/build.gradle index 1eb85d808f..ec3271e9af 100644 --- a/spring-boot-project/spring-boot-starters/spring-boot-starter-websocket/build.gradle +++ b/spring-boot-project/spring-boot-starters/spring-boot-starter-websocket/build.gradle @@ -6,6 +6,5 @@ description = "Starter for building WebSocket applications using Spring Framewor dependencies { api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) - api("org.springframework:spring-messaging") - api("org.springframework:spring-websocket") + api(project(":spring-boot-project:spring-boot-websocket")) } diff --git a/spring-boot-project/spring-boot-websocket/build.gradle b/spring-boot-project/spring-boot-websocket/build.gradle new file mode 100644 index 0000000000..7400fdd620 --- /dev/null +++ b/spring-boot-project/spring-boot-websocket/build.gradle @@ -0,0 +1,25 @@ +plugins { + id "java-library" + id "org.springframework.boot.auto-configuration" + id "org.springframework.boot.deployed" + id "org.springframework.boot.optional-dependencies" +} + +description = "Spring Boot WebSocket" + +dependencies { + api(project(":spring-boot-project:spring-boot")) + api("org.springframework:spring-messaging") + api("org.springframework:spring-websocket") + + optional(project(":spring-boot-project:spring-boot-autoconfigure")) + optional(project(":spring-boot-project:spring-boot-jackson")) + + testImplementation(project(":spring-boot-project:spring-boot-test")) + testImplementation(project(":spring-boot-project:spring-boot-tomcat")) + testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support")) + testImplementation(project(":spring-boot-project:spring-boot-webmvc")) + testImplementation("org.apache.tomcat.embed:tomcat-embed-websocket") + + testRuntimeOnly("ch.qos.logback:logback-classic") +} diff --git a/spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfiguration.java b/spring-boot-project/spring-boot-websocket/src/main/java/org/springframework/boot/websocket/autoconfigure/servlet/WebSocketMessagingAutoConfiguration.java similarity index 98% rename from spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfiguration.java rename to spring-boot-project/spring-boot-websocket/src/main/java/org/springframework/boot/websocket/autoconfigure/servlet/WebSocketMessagingAutoConfiguration.java index 143e9e23af..78a9908099 100644 --- a/spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfiguration.java +++ b/spring-boot-project/spring-boot-websocket/src/main/java/org/springframework/boot/websocket/autoconfigure/servlet/WebSocketMessagingAutoConfiguration.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.websocket.servlet; +package org.springframework.boot.websocket.autoconfigure.servlet; import java.util.List; import java.util.Map; @@ -49,7 +49,7 @@ import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerCo * @author Andy Wilkinson * @author Lasse Wulff * @author Moritz Halbritter - * @since 1.3.0 + * @since 4.0.0 */ @AutoConfiguration(afterName = "org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration") @ConditionalOnWebApplication(type = Type.SERVLET) diff --git a/spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/websocket/servlet/package-info.java b/spring-boot-project/spring-boot-websocket/src/main/java/org/springframework/boot/websocket/autoconfigure/servlet/package-info.java similarity index 84% rename from spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/websocket/servlet/package-info.java rename to spring-boot-project/spring-boot-websocket/src/main/java/org/springframework/boot/websocket/autoconfigure/servlet/package-info.java index 0f73bdf379..29d71a3441 100644 --- a/spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/websocket/servlet/package-info.java +++ b/spring-boot-project/spring-boot-websocket/src/main/java/org/springframework/boot/websocket/autoconfigure/servlet/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,4 +17,4 @@ /** * Auto-configuration for WebSocket support in servlet web servers. */ -package org.springframework.boot.autoconfigure.websocket.servlet; +package org.springframework.boot.websocket.autoconfigure.servlet; diff --git a/spring-boot-project/spring-boot-websocket/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-project/spring-boot-websocket/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000000..85617d3fdd --- /dev/null +++ b/spring-boot-project/spring-boot-websocket/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +org.springframework.boot.websocket.autoconfigure.servlet.WebSocketMessagingAutoConfiguration diff --git a/spring-boot-project/spring-boot-autoconfigure-all/src/test/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfigurationTests.java b/spring-boot-project/spring-boot-websocket/src/test/java/org/springframework/boot/websocket/autoconfigure/servlet/WebSocketMessagingAutoConfigurationTests.java similarity index 97% rename from spring-boot-project/spring-boot-autoconfigure-all/src/test/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfigurationTests.java rename to spring-boot-project/spring-boot-websocket/src/test/java/org/springframework/boot/websocket/autoconfigure/servlet/WebSocketMessagingAutoConfigurationTests.java index 4fa34e3359..390df53120 100644 --- a/spring-boot-project/spring-boot-autoconfigure-all/src/test/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-websocket/src/test/java/org/springframework/boot/websocket/autoconfigure/servlet/WebSocketMessagingAutoConfigurationTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.websocket.servlet; +package org.springframework.boot.websocket.autoconfigure.servlet; import java.lang.reflect.Type; import java.util.ArrayList; @@ -38,7 +38,6 @@ import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.boot.LazyInitializationBeanFactoryPostProcessor; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration; -import org.springframework.boot.autoconfigure.websocket.servlet.WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration; import org.springframework.boot.test.util.TestPropertyValues; @@ -47,6 +46,7 @@ import org.springframework.boot.tomcat.autoconfigure.servlet.TomcatServletWebSer import org.springframework.boot.tomcat.servlet.TomcatServletWebServerFactory; import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.boot.webmvc.autoconfigure.DispatcherServletAutoConfiguration; +import org.springframework.boot.websocket.autoconfigure.servlet.WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; @@ -146,7 +146,7 @@ class WebSocketMessagingAutoConfigurationTests { void predefinedThreadExecutorIsSelectedForInboundChannel() { AsyncTaskExecutor expectedExecutor = new SimpleAsyncTaskExecutor(); ChannelRegistration registration = new ChannelRegistration(); - WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration( + WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration( new ObjectMapper(), Map.of(TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME, expectedExecutor)); configuration.configureClientInboundChannel(registration);