|
此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Boot 3.5.5! |
通过 JMX 进行监控和管理
Java 管理扩展 (JMX) 提供了一种标准机制来监视和管理应用程序。
默认情况下,此功能未启用。
您可以通过设置spring.jmx.enabled配置属性设置为true.
Spring Boot 暴露最合适的MBeanServer作为 ID 为mbeanServer.
任何使用 Spring JMX 注释(@org.springframework.jmx.export.annotation.ManagedResource,@ManagedAttribute或@ManagedOperation)暴露于其中。
如果您的平台提供标准MBeanServer,Spring Boot 使用它并默认为 VMMBeanServer,如有必要。
如果所有这些都失败了,则新的MBeanServer被创建。
请参阅JmxAutoConfigurationclass 了解更多详情。
默认情况下,Spring Boot 还将管理端点公开为 JMX MBeanorg.springframework.boot域。
要完全控制 JMX 域中的端点注册,请考虑注册您自己的端点EndpointObjectNameFactory实现。
自定义 MBean 名称
MBean 的名称通常从id的端点。
例如,healthendpoint 公开为org.springframework.boot:type=Endpoint,name=Health.
如果您的应用程序包含多个 SpringApplicationContext,您可能会发现名称冲突。
要解决此问题,您可以将spring.jmx.unique-names属性设置为true因此 MBean 名称始终是唯一的。
您还可以自定义在下公开端点的 JMX 域。
以下设置显示了在application.properties:
-
Properties
-
YAML
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属性设置为 ,如以下示例所示:*
-
Properties
-
YAML
management.endpoints.jmx.exposure.exclude=*
management:
endpoints:
jmx:
exposure:
exclude: "*"