如何使用Spring Boot配置JMX [英] How to configure JMX with Spring Boot
问题描述
我已经用Spring Boot创建了一个Spring Integration应用程序.我想知道如何使用Spring Boot配置JMX.我相信默认情况下,使用Spring Boot Actuator时会配置JMX.
I have created a Spring Integration application with Spring Boot. I would like to know how to configure JMX with Spring Boot. I believe by default JMX is configured when using Spring Boot Actuator.
我是否需要进行其他配置才能导出MBean以进行Spring集成?
Do I need to configure anything else to be able to export MBeans for Spring Integration?
我看到的大多数示例在applicationContext.xml中都有以下行
Most of the example I see have the following line in the applicationContext.xml
<context:mbean-export/>
<context:mbean-server/>
我的Application.java类看起来像这样.
My Application.java class looks like this.
package com.jbhunt.app.consumerappointmentintegration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
@Configuration
@ComponentScan
@EnableAutoConfiguration
@ImportResource("classpath:META-INF/spring/integration/spring-integration-context.xml")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
在配置中添加此行似乎不会导出Spring Integration mbeans
Adding this line to the configuration doesn't seem to export the Spring Integration mbeans
@EnableIntegrationMBeanExport(server = "mbeanServer", defaultDomain="my.company.domain")
我正在引用此视频 https://www.youtube.com/watch?v= TetfR7ULnA8
推荐答案
据您了解,如果您仅在类路径中使用spring-integration-jmx
,则默认情况下会启用Spring Integration JMX.当然,如果spring.jmx.enabled = true
(默认).
As you understand the Spring Integration JMX is enabled by default, if you just have spring-integration-jmx
in the classpath. And, of course, if spring.jmx.enabled = true
(default).
不能仅仅声明一个@EnableIntegrationMBeanExport
就覆盖它,因为它基于@Import
并且由于(from ConfigurationClassParser
)而不能覆盖导入类:
You can't overrride that just declaring one more @EnableIntegrationMBeanExport
, because it is based on @Import
and you just can't override import classes because of (from ConfigurationClassParser
):
imports.addAll(sourceClass.getAnnotationAttributes(Import.class.getName(), "value"));
如果导入的类已经存在,则它们不可重写.
If imported classes are already there, they aren't overridable.
您有几种选择可以满足您的要求:
You have several choices to achieve your requirements:
-
禁用默认的Spring Boot JMX-只需将addind添加到
application.properties
spring.jmx.enabled = false
并继续使用@EnableIntegrationMBeanExport
手动配置IntegrationMBeanExporter
@Bean
.
只需在application.properties
中配置您的my.company.domain
域:
spring.jmx.default_domain = my.company.domain
这篇关于如何使用Spring Boot配置JMX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!