1

When using spring data mongo, how can you do <mongo:jmx /> in java based config?

1
  • I am looking for this too :) Commented Apr 16, 2015 at 14:36

1 Answer 1

2

Spring does not (yet?) support this. You have two options:

  1. Include all beans in Java Config

Beans are found in 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;
}
  1. Create a minimal xml-config

Recommended since beans might change for new releases.

In JavaConfig:

@ImportResource("classpath:spring.xml")

under src/main/resources add a file 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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.