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

如何让Spring Boot Actuator与Camel使用相同的contextPath?

实现Spring Boot Actuator与Camel共用context-path的配置方案

该需求可以实现,你之前两种方案失败的原因分别是:

  • 配置server.servlet.context-path后,Camel的camel.component.servlet.mapping.contextPath参数是相对于全局Servlet上下文路径生效的,叠加后路径与预期不符,导致路由访问失效
  • management.endpoints.web.base-path参数不支持通配符**,且默认会自动继承全局server.servlet.context-path,错误配置通配符会导致路径匹配失败

正确配置步骤(application.yml)

# 1. 配置全局Servlet上下文路径
server:
  servlet:
    context-path: ${CONTEXT_PATH:/api-context}

# 2. 调整Camel Servlet映射路径
camel:
  component:
    servlet:
      mapping:
        # 全局已经加了/api-context前缀,此处直接映射根路径即可
        contextPath: /*

# 3. 配置Actuator参数
management:
  endpoint:
    health:
      show-details: always
  endpoints:
    web:
      # 此处仅需配置actuator后缀,会自动拼接全局context-path
      base-path: /actuator
      exposure:
        # 按需暴露端点,需要其他端点可自行添加到列表中
        include: health

生效后访问路径

  • Camel路由访问地址:http://localhost:8080/api-context/[自定义路由路径],与你之前的使用习惯完全一致
  • Actuator根地址:http://localhost:8080/api-context/actuator
  • 健康检查地址:http://localhost:8080/api-context/actuator/health

特殊情况说明

如果你是手动注册ServletRegistrationBean来注册Camel Servlet,需要确保对应的addUrlMappings配置为/*,不要额外添加上下文前缀即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.27 01:45:03