Skip to content

Commit a93cf64

Browse files
committed
Make JMX endpoints available when lazy init is enabled
Closes gh-28335
1 parent a722fe4 commit a93cf64

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfiguration.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
2323
import com.fasterxml.jackson.databind.ObjectMapper;
2424

2525
import org.springframework.beans.factory.ObjectProvider;
26+
import org.springframework.boot.LazyInitializationExcludeFilter;
2627
import org.springframework.boot.actuate.autoconfigure.endpoint.expose.IncludeExcludeEndpointFilter;
2728
import org.springframework.boot.actuate.endpoint.EndpointFilter;
2829
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
@@ -103,4 +104,9 @@ public IncludeExcludeEndpointFilter<ExposableJmxEndpoint> jmxIncludeExcludePrope
103104
exposure.getExclude(), "*");
104105
}
105106

107+
@Bean
108+
static LazyInitializationExcludeFilter eagerlyInitializeJmxEndpointExporter() {
109+
return LazyInitializationExcludeFilter.forBeanTypes(JmxEndpointExporter.class);
110+
}
111+
106112
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/JmxEndpointIntegrationTests.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
2626

2727
import org.junit.jupiter.api.Test;
2828

29+
import org.springframework.boot.LazyInitializationBeanFactoryPostProcessor;
2930
import org.springframework.boot.actuate.audit.InMemoryAuditEventRepository;
3031
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
3132
import org.springframework.boot.actuate.autoconfigure.endpoint.jmx.JmxEndpointAutoConfiguration;
@@ -66,6 +67,16 @@ void jmxEndpointsAreExposed() {
6667
});
6768
}
6869

70+
@Test
71+
void jmxEndpointsAreExposedWhenLazyInitializationIsEnabled() {
72+
this.contextRunner.withBean(LazyInitializationBeanFactoryPostProcessor.class,
73+
LazyInitializationBeanFactoryPostProcessor::new).run((context) -> {
74+
MBeanServer mBeanServer = context.getBean(MBeanServer.class);
75+
checkEndpointMBeans(mBeanServer, new String[] { "beans", "conditions", "configprops", "env",
76+
"health", "info", "mappings", "threaddump", "httptrace" }, new String[] { "shutdown" });
77+
});
78+
}
79+
6980
@Test
7081
void jmxEndpointsCanBeExcluded() {
7182
this.contextRunner.withPropertyValues("management.endpoints.jmx.exposure.exclude:*").run((context) -> {

0 commit comments

Comments
 (0)