搜索

2.4. 运行 Spring Boot 应用程序

download PDF

您可以通过两个步骤将 HawtIO 附加到 Spring Boot 应用程序。

流程

  1. 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>
  2. 通过在 application.properties 中添加以下行来启用 HawtIO 和 Jolokia 端点:

    spring.jmx.enabled = true
    management.endpoints.web.exposure.include = hawtio,jolokia
  3. 在开发模式下使用 Spring Boot 应用程序运行 HawtIO,如下所示:

    mvn spring-boot:run
  4. 打开 http://localhost:8080/actuator/hawtio 以查看 HawtIO 控制台。

2.4.1. 配置 HawtIO 路径

如果您不希望具有 HawtIO 端点的 /actuator 基本路径,您也可以执行以下操作:

  1. 使用 management.endpoints.web.base-path 属性自定义 Spring Boot 管理基础路径:

    management.endpoints.web.base-path = /
  2. 您还可以通过设置 management.endpoints.web.path-mapping.hawtio 属性来自定义 HawtIO 端点的路径:

    management.endpoints.web.path-mapping.hawtio = hawtio/console
  3. Example:

    1. 有一个正常工作的 Spring Boot 示例,它演示了如何监控一个 Web 应用程序,它公开 Apache Camel 路由、指标等信息,其中包含 HawtIO Spring Boot 示例
    2. 用于实时值和图表的良好 MBean 是 java.lang/OperatingSystem。尝试查看 Camel 路由。请注意,当您更改树中的选择时,根据内容动态更改可用选项卡列表。
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.