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

Spring Boot升级至3.1.2后迁移javax到jakarta遇JMX服务URL获取失败

解决Spring Boot 3.1.2升级后IntelliJ提示“Failed to retrieve application JMX service URL”问题

问题背景

  • 原技术栈:Java 17 + Spring Boot 2.6.4
  • 升级原因:需引入spring-data-jpa-datatables依赖,该依赖与Spring Boot 2.6.4不兼容,因此升级至Spring Boot 3.1.2
  • 同步变更:完成javax到jakarta的包路径替换,Spring Security 5到6的迁移
  • 问题现象:应用启动后控制台无报错,但IntelliJ IDEA持续提示“Failed to retrieve application JMX service URL”

解决方案建议

1. 显式配置JMX参数

Spring Boot 3.x对JMX默认配置做了调整,可在配置文件中显式开启并配置JMX:
application.properties示例:

spring.jmx.enabled=true
management.endpoints.jmx.exposure.include=*
management.endpoint.jmx.enabled=true

application.yml示例:

spring:
  jmx:
    enabled: true
management:
  endpoints:
    jmx:
      exposure:
        include: '*'
  endpoint:
    jmx:
      enabled: true

2. 调整IntelliJ启动配置

  • 打开「Run/Debug Configurations」,找到当前应用的启动项
  • 切换到「Configuration」标签,找到「JMX」模块,勾选「Enable JMX agent」
  • 可手动指定固定端口(如1099),避免端口占用导致的连接失败
  • 保存配置后重新启动应用

3. 排查JMX相关依赖冲突

执行Maven命令查看依赖树,排查是否存在JMX相关的依赖冲突:

mvn dependency:tree

重点检查jakarta.management或javax.management相关包,若发现重复或版本不一致的依赖,在pom.xml中通过<exclusions>标签排除冲突项。

4. 调整Spring Security 6的JMX权限配置

Spring Security 6对端点权限控制更严格,需确保JMX相关的Actuator端点被允许访问:

@Configuration
public class SecurityConfig {
    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
            .authorizeHttpRequests(auth -> auth
                .requestMatchers("/actuator/jmx/**").permitAll()
                // 其他业务接口的权限配置
            )
            // 其他Security配置(如CSRF、表单登录等)
            .csrf(csrf -> csrf.disable()); // 根据实际场景调整
        return http.build();
    }
}

5. 清理缓存并重建项目

  • 执行IntelliJ的「File -> Invalidate Caches...」,选择「Invalidate and Restart」清理IDE缓存
  • 执行mvn clean install清理并重新构建项目,再启动应用

若提供完整的pom.xml和主启动类代码,可进一步精准排查潜在的配置或依赖问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 07:20:52