此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Boot 3.4.0spring-doc.cadn.net.cn

通过 JMX 进行监控和管理

Java 管理扩展 (JMX) 提供了一种用于监视和管理应用程序的标准机制。 默认情况下,此功能未启用。 您可以通过设置spring.jmx.enabledconfiguration 属性设置为true. Spring Boot 公开了最合适的MBeanServer作为 ID 为mbeanServer. 任何使用 Spring JMX 注释 (@org.springframework.jmx.export.annotation.ManagedResource,@ManagedAttribute@ManagedOperation) 会接触到它。spring-doc.cadn.net.cn

如果您的平台提供标准的MBeanServer,Spring Boot 会使用该 VMMBeanServer,如有必要。 如果所有这些都失败了,一个新的MBeanServer已创建。spring-doc.cadn.net.cn

spring.jmx.enabled仅影响 Spring 提供的 Management bean。 启用其他库(例如 Log4j2Quartz)提供的管理 Bean 是独立的。

请参阅JmxAutoConfiguration类了解更多详情。spring-doc.cadn.net.cn

默认情况下, Spring Boot 还会将管理端点作为 JMX MBean 公开在org.springframework.boot域。 要完全控制 JMX 域中的终端节点注册,请考虑注册您自己的EndpointObjectNameFactory实现。spring-doc.cadn.net.cn

自定义 MBean 名称

MBean 的名称通常是从id的终端节点。 例如,healthendpoint 公开为org.springframework.boot:type=Endpoint,name=Health.spring-doc.cadn.net.cn

如果您的应用程序包含多个 SpringApplicationContext,您可能会发现名称冲突。 要解决此问题,您可以设置spring.jmx.unique-namesproperty 设置为true,以便 MBean 名称始终是唯一的。spring-doc.cadn.net.cn

您还可以自定义在其下公开终端节点的 JMX 域。 以下设置显示了在application.properties:spring-doc.cadn.net.cn

spring.jmx.unique-names=true
management.endpoints.jmx.domain=com.example.myapp
spring:
  jmx:
    unique-names: true
management:
  endpoints:
    jmx:
      domain: "com.example.myapp"

禁用 JMX 端点

如果您不想通过 JMX 公开端点,则可以设置management.endpoints.jmx.exposure.exclude属性设置为 ,如下例所示:*spring-doc.cadn.net.cn

management.endpoints.jmx.exposure.exclude=*
management:
  endpoints:
    jmx:
      exposure:
        exclude: "*"