2.4. 运行 Spring Boot 应用程序
您可以通过两个步骤将 HawtIO 附加到 Spring Boot 应用程序。
流程
将
io.hawt:hawtio-springboot
和支持 Camel Spring Boot 启动程序添加到pom.xml
中的依赖项:<dependencyManagement> <dependencies> <dependency> <groupId>io.hawt</groupId> <artifactId>hawtio-bom</artifactId> <version>4.0.0.redhat-00072</version> <type>pom</type> <scope>import</scope> </dependency> <!-- ... other BOMs or dependencies ... --> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>io.hawt</groupId> <artifactId>hawtio-springboot</artifactId> </dependency> <!-- Mandatory for enabling Camel management via JMX / Hawtio --> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-management-starter</artifactId> </dependency> <!-- (Optional) Required for Hawtio Camel route diagram tab --> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-spring-boot-xml-starter</artifactId> </dependency> <!-- ... other dependencies ... --> </dependencies>
通过在
application.properties
中添加以下行来启用 HawtIO 和 Jolokia 端点:spring.jmx.enabled = true management.endpoints.web.exposure.include = hawtio,jolokia
在开发模式下使用 Spring Boot 应用程序运行 HawtIO,如下所示:
mvn spring-boot:run
- 打开 http://localhost:8080/actuator/hawtio 以查看 HawtIO 控制台。
2.4.1. 配置 HawtIO 路径
如果您不希望具有 HawtIO 端点的 /actuator
基本路径,您也可以执行以下操作:
使用
management.endpoints.web.base-path
属性自定义 Spring Boot 管理基础路径:management.endpoints.web.base-path = /
您还可以通过设置
management.endpoints.web.path-mapping.hawtio
属性来自定义 HawtIO 端点的路径:management.endpoints.web.path-mapping.hawtio = hawtio/console
Example:
- 有一个正常工作的 Spring Boot 示例,它演示了如何监控一个 Web 应用程序,它公开 Apache Camel 路由、指标等信息,其中包含 HawtIO Spring Boot 示例。
-
用于实时值和图表的良好 MBean 是
java.lang/OperatingSystem
。尝试查看 Camel 路由。请注意,当您更改树中的选择时,根据内容动态更改可用选项卡列表。