嵌入Spring Boot的Hawtio UI为空且Jolokia端点JMX数据缺失排查
在Camel Spring Boot应用中嵌入Hawtio 4.0.0,已按官方指南配置,但启动后Hawtio UI为空,无任何指标数据。
当前配置
application.properties
spring.jmx.enabled=true management.endpoints.web.exposure.include=info,health,camelroutes,prometheus,hawtio,jolokia
Maven依赖
<dependency> <groupId>io.hawt</groupId> <artifactId>hawtio-springboot</artifactId> <version>4.0.0</version> </dependency> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-management-starter</artifactId> </dependency> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-spring-boot-xml-starter</artifactId> </dependency>
关键现象
- Jolokia端点响应异常:调用Jolokia版本接口返回的响应中,
info.jmx为空对象,但JConsole能正常看到所有MBeans:
{"request":{"type":"version"},"value":{"agent":"2.0.2","protocol":"7.3","details":{"agent_version":"2.0.2","agent_id":"192.168.0.115-49016-52f67539-servlet","server_product":"jetty","server_vendor":"Eclipse","server_version":"12.0.6","secured":false,"url":"http://192.168.0.115:8081/xxxxx/jolokia"},"id":"192.168.0.115-49016-52f67539-servlet","config":{"agentId":"192.168.0.115-49016-52f67539-servlet","allowErrorDetails":"false","includeStackTrace":"false"},"info":{"proxy":{},"jmx":{}}},"status":200,"timestamp":1715131260}
- 日志无错误:访问Hawtio UI或Jolokia端点时,日志仅输出DEBUG级别的正常访问信息,无异常或错误日志:
- Hawtio UI访问日志:
2024-05-07T18:27:20.252-07:00 DEBUG 49016 --- [xxxxx] [ XNIO-1 task-2] io.hawt.web.auth.LoginRedirectFilter : Check if path [/xxxxx/hawtio/index.html] requires redirect 2024-05-07T18:27:20.252-07:00 DEBUG 49016 --- [xxxxx] [ XNIO-1 task-2] io.hawt.web.filters.BaseTagHrefFilter : baseTagHref = /xxxxx/hawtio 2024-05-07T18:27:20.274-07:00 DEBUG 49016 --- [xxxxx] [ XNIO-1 task-2] io.hawt.web.auth.SessionExpiryFilter : Accessing [/xxxxx/hawtio/static/js/main.d0c4c242.js], hawtio- Jolokia端点访问日志:
2024-05-07T18:23:50.315-07:00 DEBUG 49016 --- [xxxxx] [ XNIO-1 task-2] io.hawt.web.auth.AuthenticationFilter : Handling request for path: /xxxxx/jolokia 2024-05-07T18:23:50.315-07:00 DEBUG 49016 --- [xxxxx] [ XNIO-1 task-2] io.hawt.web.auth.AuthenticationFilter : No authentication needed for path: /xxxxx/jolokia
版本信息
- Camel: 4.5
- Hawtio: 4.0.0
- Spring Boot: 3.2.3
- Jolokia: 2.0.2
核心问题是Jolokia无法正确获取JMX MBean数据,导致Hawtio UI无内容,可按以下步骤排查修复:
1. 放开Jolokia的JMX访问权限
Jolokia默认可能限制MBean访问,即使JConsole可见,也会被拦截。在application.properties添加配置:
jolokia.policy-path=classpath:/jolokia-access.xml
在src/main/resources下创建jolokia-access.xml文件,内容如下:
<restrict> <allow> <mbean> <name>*:*</name> </mbean> <operation>read,write,exec</operation> </allow> </restrict>
该配置允许Jolokia访问所有MBean的读、写、执行操作,适合开发环境调试。
2. 显式启用Camel JMX管理
虽然已引入camel-management-starter,仍需显式开启Camel的JMX注册:
camel.jmx.enabled=true camel.jmx.agent-id=camel-agent
确保Camel所有MBean都注册到JMX服务器,供Jolokia发现。
3. 修正Spring Boot JMX暴露配置
Spring Boot 3.x对JMX默认配置有调整,需确保管理端点的JMX暴露正确:
management.endpoints.jmx.exposure.include=* management.endpoint.jolokia.enabled=true
保证Jolokia端点能正确桥接JMX数据。
4. 验证Jolokia数据获取能力
重启应用后,调用Jolokia的MBean列表接口:
GET http://your-host:8081/xxxxx/jolokia/list
若返回包含Camel、Spring相关的MBean数据,说明问题已解决;若仍为空,需检查:
- 是否存在自定义JMX服务器配置,导致Jolokia连接到错误的MBeanServer
- 应用是否有安全管理器(SecurityManager)限制Jolokia访问
management.server.base-path是否与上下文路径/xxxxx/冲突
5. 对齐Hawtio上下文路径
若Jolokia数据正常但Hawtio UI仍为空,检查Hawtio路径配置:
hawtio.path=/xxxxx/hawtio
确保该路径与实际访问的Hawtio UI路径一致,避免路径不匹配导致数据加载失败。
内容的提问来源于stack exchange,提问作者user3029642

