You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3.0.3中EnableWebSocketMessageBroker的404问题求助

Spring Boot 3.0.3中WebSocket官方示例/gs-guide-websocket/info接口404问题

问题描述

测试Spring WebSocket官方示例时发现,Spring Boot 3.0.2版本运行完全正常,但升级到3.0.3版本后,访问/gs-guide-websocket/info接口出现404错误。想确认是否有其他开发者遇到相同问题,或是了解该版本的相关Bug。

条件评估报告日志

2023-02-27T12:44:14.955+01:00 DEBUG 17724 --- [           main] .s.b.a.l.ConditionEvaluationReportLogger : 


============================
条件评估报告
============================


匹配成功项:
-----------------

   ...

   WebMvcAutoConfiguration 匹配成功:
      - @ConditionalOnClass 找到所需类 'jakarta.servlet.Servlet', 'org.springframework.web.servlet.DispatcherServlet', 'org.springframework.web.servlet.config.annotation.WebMvcConfigurer' (OnClassCondition)
      - 检测到'session'作用域 (OnWebApplicationCondition)
      - @ConditionalOnMissingBean (类型: org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 搜索策略: 全部) 未找到任何Bean (OnBeanCondition)

   WebMvcAutoConfiguration#formContentFilter 匹配成功:
      - @ConditionalOnProperty (spring.mvc.formcontent.filter.enabled) 匹配成功 (OnPropertyCondition)
      - @ConditionalOnMissingBean (类型: org.springframework.web.filter.FormContentFilter; 搜索策略: 全部) 未找到任何Bean (OnBeanCondition)

   WebMvcAutoConfiguration.EnableWebMvcConfiguration#flashMapManager 匹配成功:
      - @ConditionalOnMissingBean (名称: flashMapManager; 搜索策略: 全部) 未找到任何Bean (OnBeanCondition)

   WebMvcAutoConfiguration.EnableWebMvcConfiguration#localeResolver 匹配成功:
      - @ConditionalOnMissingBean (名称: localeResolver; 搜索策略: 全部) 未找到任何Bean (OnBeanCondition)

   WebMvcAutoConfiguration.EnableWebMvcConfiguration#themeResolver 匹配成功:
      - @ConditionalOnMissingBean (名称: themeResolver; 搜索策略: 全部) 未找到任何Bean (OnBeanCondition)

   WebMvcAutoConfiguration.ResourceChainCustomizerConfiguration 匹配成功:
      - @ConditionalOnEnabledResourceChain 找到类 org.webjars.WebJarAssetLocator (OnEnabledResourceChainCondition)

   WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#defaultViewResolver 匹配成功:
      - @ConditionalOnMissingBean (类型: org.springframework.web.servlet.view.InternalResourceViewResolver; 搜索策略: 全部) 未找到任何Bean (OnBeanCondition)

   WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#requestContextFilter 匹配成功:
      - @ConditionalOnMissingBean (类型: org.springframework.web.context.request.RequestContextListener,org.springframework.web.filter.RequestContextFilter; 搜索策略: 全部) 未找到任何Bean (OnBeanCondition)

   WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#viewResolver 匹配成功:
      - @ConditionalOnBean (类型: org.springframework.web.servlet.ViewResolver; 搜索策略: 全部) 找到Bean 'defaultViewResolver', 'beanNameViewResolver', 'mvcViewResolver'; @ConditionalOnMissingBean (名称: viewResolver 类型: org.springframework.web.servlet.view.ContentNegotiatingViewResolver; 搜索策略: 全部) 未找到任何Bean (OnBeanCondition)

   WebSocketMessagingAutoConfiguration 匹配成功:
      - @ConditionalOnClass 找到所需类 'org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer' (OnClassCondition)
      - 检测到'session'作用域 (OnWebApplicationCondition)

   WebSocketServletAutoConfiguration 匹配成功:
      - @ConditionalOnClass 找到所需类 'jakarta.servlet.Servlet', 'jakarta.websocket.server.ServerContainer' (OnClassCondition)
      - 检测到'session'作用域 (OnWebApplicationCondition)

   WebSocketServletAutoConfiguration.TomcatWebSocketConfiguration 匹配成功:
      - @ConditionalOnClass 找到所需类 'org.apache.catalina.startup.Tomcat', 'org.apache.tomcat.websocket.server.WsSci' (OnClassCondition)

   WebSocketServletAutoConfiguration.TomcatWebSocketConfiguration#websocketServletWebServerCustomizer 匹配成功:
      - @ConditionalOnMissingBean (名称: websocketServletWebServerCustomizer; 搜索策略: 全部) 未找到任何Bean (OnBeanCondition)


匹配失败项:
-----------------

   ...

   WebClientAutoConfiguration:
      匹配失败:
         - @ConditionalOnClass 未找到所需类 'org.springframework.web.reactive.function.client.WebClient' (OnClassCondition)

   WebFluxAutoConfiguration:
      匹配失败:
         - @ConditionalOnClass 未找到所需类 'org.springframework.web.reactive.config.WebFluxConfigurer' (OnClassCondition)

   WebMvcAutoConfiguration#hiddenHttpMethodFilter:
      匹配失败:
         - @ConditionalOnProperty (spring.mvc.hiddenmethod.filter.enabled) 未找到属性'enabled' (OnPropertyCondition)

   WebMvcAutoConfiguration.ProblemDetailsErrorHandlingConfiguration:
      匹配失败:
         - @ConditionalOnProperty (spring.mvc.problemdetails.enabled=true) 未找到属性'enabled' (OnPropertyCondition)

   WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#beanNameViewResolver:
      匹配失败:
         - @ConditionalOnMissingBean (类型: org.springframework.web.servlet.view.BeanNameViewResolver; 搜索策略: 全部) 找到类型为'org.springframework.web.servlet.view.BeanNameViewResolver'的Bean beanNameViewResolver (OnBeanCondition)

   WebServiceTemplateAutoConfiguration:
      匹配失败:
         - @ConditionalOnClass 未找到所需类 'org.springframework.oxm.Marshaller' (OnClassCondition)

   WebServicesAutoConfiguration:
      匹配失败:
         - @ConditionalOnClass 未找到所需类 'org.springframework.ws.transport.http.MessageDispatcherServlet' (OnClassCondition)

   WebSessionIdResolverAutoConfiguration:
      匹配失败:
         - @ConditionalOnClass 未找到所需类 'reactor.core.publisher.Mono' (OnClassCondition)

   WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration:
      匹配失败:
         - @ConditionalOnBean (类型: org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration,com.fasterxml.jackson.databind.ObjectMapper; 搜索策略: 全部) 未找到任何类型为org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration的Bean (OnBeanCondition)
      匹配成功项:
         - @ConditionalOnClass 找到所需类 'com.fasterxml.jackson.databind.ObjectMapper', 'org.springframework.messaging.simp.config.AbstractMessageBrokerConfiguration' (OnClassCondition)

   WebSocketReactiveAutoConfiguration:
      匹配失败:
         - @ConditionalOnWebApplication 未找到响应式Web应用类 (OnWebApplicationCondition)

   WebSocketServletAutoConfiguration.JettyWebSocketConfiguration:
      匹配失败:
         - @ConditionalOnClass 未找到所需类 'org.eclipse.jetty.websocket.jakarta.server.config.JakartaWebSocketServletContainerInitializer' (OnClassCondition)

   WebSocketServletAutoConfiguration.UndertowWebSocketConfiguration:
      匹配失败:
         - @ConditionalOnClass 未找到所需类 'io.undertow.websockets.jsr.Bootstrap' (OnClassCondition)

   XADataSourceAutoConfiguration:
      匹配失败:
         - @ConditionalOnClass 未找到所需类 'jakarta.transaction.TransactionManager' (OnClassCondition)


排除项:
-----------

    无


无条件加载类:
----------------------

    org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration

    org.springframework.boot.autoconfigure.context.LifecycleAutoConfiguration

    org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration

    org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration

    org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration

问题分析与解决

这是Spring Boot 3.0.3版本的已知回归Bug,根源在于Spring Framework 6.0.5(Spring Boot 3.0.3对应的框架版本)中,STOMP WebSocket的/info端点映射逻辑出现异常,导致SockJS依赖的该端点未被正确注册。

可用解决方案:

  1. 降级版本:直接回退到Spring Boot 3.0.2,该版本无此问题。
  2. 手动处理端点请求:在WebSocket配置类中添加自定义拦截器,手动响应/info请求,代码示例:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/gs-guide-websocket")
                .withSockJS()
                .setInterceptors(infoInterceptor());
    }

    @Bean
    public HttpSessionHandshakeInterceptor infoInterceptor() {
        return new HttpSessionHandshakeInterceptor() {
            @Override
            public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
                if (request.getURI().getPath().endsWith("/info")) {
                    response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
                    response.getBody().write("{\"entropy\": \"random-string\", \"heartbeat\": [0, 0]}".getBytes());
                    return false;
                }
                return super.beforeHandshake(request, response, wsHandler, attributes);
            }
        };
    }

    // 原有配置代码...
}
  1. 升级修复版本:Spring Boot 3.0.4及后续版本已修复该Bug,建议直接升级到最新稳定版。

内容的提问来源于stack exchange,提问作者Benjamin Schüller

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 08:12:05