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

Spring Boot 3配置WebSocket安全时找不到MessageMatcherDelegatingAuthorizationManager类

问题排查与解决

1. 类的正确位置

在Spring Security 6.x(对应Spring Boot 3.x)版本中,MessageMatcherDelegatingAuthorizationManager的全类名已更新为:

org.springframework.security.messaging.access.intercept.MessageMatcherDelegatingAuthorizationManager

若文档标注的是旧包路径(比如org.springframework.security.messaging.access),属于文档滞后问题,请使用上述正确路径尝试导入。

2. 缺失必要依赖

spring-boot-starter-security默认不包含WebSocket消息安全所需的spring-security-messaging模块,你需要在pom.xml中手动添加该依赖:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-messaging</artifactId>
</dependency>

由于你使用spring-boot-starter-parent:3.0.4做依赖版本管理,无需指定版本号,会自动匹配兼容的Spring Security 6.0.3版本。

3. 验证配置示例

添加依赖后,可参考以下示例配置WebSocket安全:

@Configuration
@EnableWebSocketSecurity
public class WebSocketSecurityConfig {

    @Bean
    public MessageMatcherDelegatingAuthorizationManager messageAuthorizationManager() {
        MessageMatcherDelegatingAuthorizationManager.Builder builder = 
            MessageMatcherDelegatingAuthorizationManager.builder();
        
        // 配置消息权限规则,例如允许认证用户订阅指定目的地
        builder.simpDestMatchers("/topic/**").authenticated();
        // 其他规则配置...
        
        return builder.build();
    }
}

内容的提问来源于stack exchange,提问作者Szőke Attila

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 17:24:55