Skip to content

Commit 0c8f955

Browse files
committed
Merge branch '4.0.x'
Closes gh-49198
2 parents 4f4b93d + 9c6d1d2 commit 0c8f955

File tree

5 files changed

+70
-34
lines changed

5 files changed

+70
-34
lines changed

module/spring-boot-webflux/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,8 @@ dependencies {
6363
tasks.named("compileTestJava") {
6464
options.nullability.checking = "tests"
6565
}
66+
67+
tasks.named("test") {
68+
jvmArgs += "--add-opens=java.base/java.net=ALL-UNNAMED"
69+
}
70+

module/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/autoconfigure/actuate/web/WebFluxEndpointManagementContextConfiguration.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.springframework.boot.webflux.actuate.endpoint.web.AdditionalHealthEndpointPathsWebFluxHandlerMapping;
5959
import org.springframework.boot.webflux.actuate.endpoint.web.WebFluxEndpointHandlerMapping;
6060
import org.springframework.context.annotation.Bean;
61+
import org.springframework.context.annotation.Configuration;
6162
import org.springframework.context.annotation.Role;
6263
import org.springframework.core.codec.Encoder;
6364
import org.springframework.core.env.Environment;
@@ -113,21 +114,6 @@ private boolean shouldRegisterLinksMapping(WebEndpointProperties properties, Env
113114
|| ManagementPortType.get(environment) == ManagementPortType.DIFFERENT);
114115
}
115116

116-
@Bean
117-
@ConditionalOnManagementPort(ManagementPortType.DIFFERENT)
118-
@ConditionalOnAvailableEndpoint(endpoint = HealthEndpoint.class, exposure = EndpointExposure.WEB)
119-
@ConditionalOnBean(HealthEndpoint.class)
120-
public AdditionalHealthEndpointPathsWebFluxHandlerMapping managementHealthEndpointWebFluxHandlerMapping(
121-
WebEndpointsSupplier webEndpointsSupplier, HealthEndpointGroups groups) {
122-
Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
123-
ExposableWebEndpoint healthEndpoint = webEndpoints.stream()
124-
.filter((endpoint) -> endpoint.getEndpointId().equals(HealthEndpoint.ID))
125-
.findFirst()
126-
.orElse(null);
127-
return new AdditionalHealthEndpointPathsWebFluxHandlerMapping(new EndpointMapping(""), healthEndpoint,
128-
groups.getAllWithAdditionalPath(WebServerNamespace.MANAGEMENT));
129-
}
130-
131117
@Bean
132118
@ConditionalOnMissingBean
133119
@SuppressWarnings("removal")
@@ -161,6 +147,27 @@ static ServerCodecConfigurerEndpointJackson2JsonMapperBeanPostProcessor serverCo
161147
SingletonSupplier.of(endpointJsonMapper::getObject));
162148
}
163149

150+
@Configuration(proxyBeanMethods = false)
151+
@ConditionalOnClass(HealthEndpoint.class)
152+
static class HealthConfiguration {
153+
154+
@Bean
155+
@ConditionalOnManagementPort(ManagementPortType.DIFFERENT)
156+
@ConditionalOnAvailableEndpoint(endpoint = HealthEndpoint.class, exposure = EndpointExposure.WEB)
157+
@ConditionalOnBean(HealthEndpoint.class)
158+
AdditionalHealthEndpointPathsWebFluxHandlerMapping managementHealthEndpointWebFluxHandlerMapping(
159+
WebEndpointsSupplier webEndpointsSupplier, HealthEndpointGroups groups) {
160+
Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
161+
ExposableWebEndpoint healthEndpoint = webEndpoints.stream()
162+
.filter((endpoint) -> endpoint.getEndpointId().equals(HealthEndpoint.ID))
163+
.findFirst()
164+
.orElse(null);
165+
return new AdditionalHealthEndpointPathsWebFluxHandlerMapping(new EndpointMapping(""), healthEndpoint,
166+
groups.getAllWithAdditionalPath(WebServerNamespace.MANAGEMENT));
167+
}
168+
169+
}
170+
164171
/**
165172
* {@link BeanPostProcessor} to apply {@link EndpointJsonMapper} for
166173
* {@link OperationResponseBody} to {@link JacksonJsonEncoder} instances.

module/spring-boot-webflux/src/test/java/org/springframework/boot/webflux/autoconfigure/actuate/web/WebFluxManagementChildContextConfigurationIntegrationTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext;
4242
import org.springframework.boot.test.context.runner.ContextConsumer;
4343
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
44+
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
45+
import org.springframework.boot.testsupport.web.servlet.DirtiesUrlFactories;
4446
import org.springframework.boot.tomcat.TomcatWebServer;
4547
import org.springframework.boot.tomcat.autoconfigure.actuate.web.server.TomcatReactiveManagementContextAutoConfiguration;
4648
import org.springframework.boot.tomcat.autoconfigure.reactive.TomcatReactiveWebServerAutoConfiguration;
@@ -64,6 +66,7 @@
6466
*
6567
* @author Andy Wilkinson
6668
*/
69+
@DirtiesUrlFactories
6770
class WebFluxManagementChildContextConfigurationIntegrationTests {
6871

6972
private final List<WebServer> webServers = new ArrayList<>();
@@ -124,6 +127,12 @@ void accessLogHasManagementServerSpecificPrefix() {
124127
});
125128
}
126129

130+
@Test
131+
@ClassPathExclusions(packages = "org.springframework.boot.health.actuate.endpoint")
132+
void refreshSucceedsWithoutHealth() {
133+
this.runner.run((context) -> assertThat(context).hasNotFailed());
134+
}
135+
127136
private @Nullable AccessLogValve findAccessLogValve() {
128137
assertThat(this.webServers).hasSize(2);
129138
Tomcat tomcat = ((TomcatWebServer) this.webServers.get(1)).getTomcat();

module/spring-boot-webmvc/src/main/java/org/springframework/boot/webmvc/autoconfigure/actuate/web/WebMvcEndpointManagementContextConfiguration.java

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.springframework.boot.actuate.endpoint.web.WebEndpointsSupplier;
4545
import org.springframework.boot.actuate.endpoint.web.WebServerNamespace;
4646
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
47+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
4748
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
4849
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
4950
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
@@ -54,6 +55,7 @@
5455
import org.springframework.boot.webmvc.actuate.endpoint.web.WebMvcEndpointHandlerMapping;
5556
import org.springframework.boot.webmvc.autoconfigure.DispatcherServletPath;
5657
import org.springframework.context.annotation.Bean;
58+
import org.springframework.context.annotation.Configuration;
5759
import org.springframework.context.annotation.Role;
5860
import org.springframework.core.env.Environment;
5961
import org.springframework.http.MediaType;
@@ -108,25 +110,6 @@ private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProp
108110
|| ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
109111
}
110112

111-
@Bean
112-
@ConditionalOnManagementPort(ManagementPortType.DIFFERENT)
113-
@ConditionalOnBean(HealthEndpoint.class)
114-
@ConditionalOnAvailableEndpoint(endpoint = HealthEndpoint.class, exposure = EndpointExposure.WEB)
115-
AdditionalHealthEndpointPathsWebMvcHandlerMapping managementHealthEndpointWebMvcHandlerMapping(
116-
WebEndpointsSupplier webEndpointsSupplier, HealthEndpointGroups groups) {
117-
Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
118-
ExposableWebEndpoint healthEndpoint = webEndpoints.stream()
119-
.filter(this::isHealthEndpoint)
120-
.findFirst()
121-
.orElse(null);
122-
return new AdditionalHealthEndpointPathsWebMvcHandlerMapping(healthEndpoint,
123-
groups.getAllWithAdditionalPath(WebServerNamespace.MANAGEMENT));
124-
}
125-
126-
private boolean isHealthEndpoint(ExposableWebEndpoint endpoint) {
127-
return endpoint.getEndpointId().equals(HealthEndpoint.ID);
128-
}
129-
130113
@Bean
131114
@ConditionalOnMissingBean
132115
@SuppressWarnings("removal")
@@ -169,6 +152,31 @@ static EndpointJackson2ObjectMapperWebMvcConfigurer endpointJackson2ObjectMapper
169152
return new EndpointJackson2ObjectMapperWebMvcConfigurer(endpointJsonMapper);
170153
}
171154

155+
@Configuration(proxyBeanMethods = false)
156+
@ConditionalOnClass(HealthEndpoint.class)
157+
static class HealthConfiguration {
158+
159+
@Bean
160+
@ConditionalOnManagementPort(ManagementPortType.DIFFERENT)
161+
@ConditionalOnBean(HealthEndpoint.class)
162+
@ConditionalOnAvailableEndpoint(endpoint = HealthEndpoint.class, exposure = EndpointExposure.WEB)
163+
AdditionalHealthEndpointPathsWebMvcHandlerMapping managementHealthEndpointWebMvcHandlerMapping(
164+
WebEndpointsSupplier webEndpointsSupplier, HealthEndpointGroups groups) {
165+
Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
166+
ExposableWebEndpoint healthEndpoint = webEndpoints.stream()
167+
.filter(this::isHealthEndpoint)
168+
.findFirst()
169+
.orElse(null);
170+
return new AdditionalHealthEndpointPathsWebMvcHandlerMapping(healthEndpoint,
171+
groups.getAllWithAdditionalPath(WebServerNamespace.MANAGEMENT));
172+
}
173+
174+
private boolean isHealthEndpoint(ExposableWebEndpoint endpoint) {
175+
return endpoint.getEndpointId().equals(HealthEndpoint.ID);
176+
}
177+
178+
}
179+
172180
/**
173181
* {@link WebMvcConfigurer} to apply {@link EndpointJsonMapper} for
174182
* {@link OperationResponseBody} to {@link JacksonJsonHttpMessageConverter} instances.

module/spring-boot-webmvc/src/test/java/org/springframework/boot/webmvc/autoconfigure/actuate/web/WebMvcEndpointManagementContextConfigurationTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
3131
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
3232
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
33+
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
3334
import org.springframework.boot.webmvc.autoconfigure.DispatcherServletAutoConfiguration;
3435
import org.springframework.boot.webmvc.autoconfigure.DispatcherServletPath;
3536
import org.springframework.context.annotation.Bean;
@@ -66,6 +67,12 @@ void contextWhenNotServletBasedShouldNotContainServletEndpointRegistrar() {
6667
.run((context) -> assertThat(context).doesNotHaveBean(ServletEndpointRegistrar.class));
6768
}
6869

70+
@Test
71+
@ClassPathExclusions(packages = "org.springframework.boot.health.actuate.endpoint")
72+
void refreshSucceedsWithoutHealth() {
73+
this.contextRunner.run((context) -> assertThat(context).hasNotFailed());
74+
}
75+
6976
@Configuration(proxyBeanMethods = false)
7077
@ImportAutoConfiguration(WebMvcEndpointManagementContextConfiguration.class)
7178
static class TestConfig {

0 commit comments

Comments
 (0)