使用spring data mongo时,如何在基于java的配置中执行<mongo:jmx />
?
答案 0 :(得分:2)
Spring不支持(但是?)支持这一点。您有两种选择:
在MongoJmxParser.registerJmxComponents()中可以找到豆。
@Bean
public MBeanExporter sportsbookMBeanExporter() throws MalformedObjectNameException {
MBeanExporter exporter = new MBeanExporter();
exporter.setAssembler(new SimpleReflectiveMBeanInfoAssembler());
exporter.setNamingStrategy(new MBeanObjectNamingStrategy());
Map<String, Object> beanMap = new HashMap<>();
beanMap.put("AssertMetrics", AssertMetrics.class);
beanMap.put("BackgroundFlushingMetrics", BackgroundFlushingMetrics.class);
beanMap.put("BtreeIndexCounters", BtreeIndexCounters.class);
beanMap.put("ConnectionMetrics", ConnectionMetrics.class);
beanMap.put("GlobalLockMetrics", GlobalLockMetrics.class);
beanMap.put("MemoryMetrics", MemoryMetrics.class);
beanMap.put("OperationCounters", OperationCounters.class);
beanMap.put("ServerInfo", ServerInfo.class);
beanMap.put("MongoAdmin", MongoAdmin.class);
exporter.setBeans(beanMap);
return exporter;
}
建议使用bean,因为新版本可能会更改。
在JavaConfig中:
@ImportResource("classpath:spring.xml")
在src / main / resources下添加一个文件spring.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!--not possible to enable in Java Config-->
<mongo:jmx/>
</beans>