添加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
相关产品推荐
相关产品推荐

