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

添加spring-boot-starter-security依赖致ActiveMQ崩溃求助

问题解决方案

1. 排除Spring Security对ActiveMQ路径的拦截

添加spring-boot-starter-security后,Spring Security默认会拦截所有HTTP请求,包括ActiveMQ的控制台、JMS通信相关路径,导致JMS数据包被错误解析为HTTP请求,引发解码失败、无效类型等错误。你需要在Security配置类中明确忽略这些路径:

创建或修改你的Security配置类:

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    // 忽略ActiveMQ相关路径,避免被Security拦截
    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring()
           // 适配ActiveMQ Artemis控制台路径
           .antMatchers("/console/**")
           // 适配ActiveMQ Artemis的JMS HTTP通信路径
           .antMatchers("/artemis/**")
           // 传统ActiveMQ需添加以下路径,根据实际配置调整
           .antMatchers("/admin/**", "/api/**");
    }

    // 配置API的登录验证逻辑,按你的需求实现
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/public/**").permitAll() // 开放无需验证的API
                .anyRequest().authenticated()
                .and()
            .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
            .logout()
                .permitAll();
    }
}

2. 确认ActiveMQ通信协议配置

如果你的ActiveMQ使用TCP协议而非HTTP/STOMP,Spring Security不会拦截TCP端口通信,无需额外配置。但如果是基于HTTP的JMS通信,必须确保对应路径已被加入上述忽略列表。

日志中“帧大小超过100MB限制”的警告,本质是Security错误解析JMS数据包导致的异常,解决路径拦截问题后该警告会自动消失。

3. 排查依赖冲突(可选)

若上述操作无效,可通过mvn dependency:tree命令查看依赖树,检查是否因添加Security依赖导致ActiveMQ客户端与其他组件版本冲突,必要时通过<exclusions>标签排除冲突依赖。


内容的提问来源于stack exchange,提问作者azeem

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 21:30:50