This is, I think, a documentation issue.

@SpringBootTest appears to have JMX disabled by default which causes the test to fail if there is a component that tries to inject MBeanServer. Things work as expected if @TestPropertySource(properties = "spring.jmx.enabled=true") is used.

This can be reproduced using something as simple as:

@SpringBootApplication
public class JmxDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(JmxDemoApplication.class, args);
    }

    @Autowired
    private MBeanServer mbeanServer;

}
@RunWith(SpringRunner.class)
@SpringBootTest
//@TestPropertySource(properties = "spring.jmx.enabled=true")
public class JmxDemoApplicationTests {

    @Test
    public void contextLoads() {
    }

}

There is a hint in Spring Data JPA sample app that this expected behavior however the reference manual does not mention this AFAICT.

Comment From: vpavic

Seeing this was assigned to 2.0.x, I believe 1.5.x is a more suitable target for this.

Comment From: manjuangadi

I have solved the same issue by adding the "@AutoConfigureMetrics" annotation to my "@SpringBootTest" class.

more details - https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.testing.spring-boot-applications.jmx