Skip to content

Commit ba87b2e

Browse files
committed
Avoid loading health classes in Cloud Foundry
Move the Cloud Foundry health endpoint extension bean into a health-specific configuration. This lets the actuator configuration refresh when spring-boot-health is absent. Signed-off-by: Lee JiWon <dlwldnjs1009@gmail.com>
1 parent 525006c commit ba87b2e

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

module/spring-boot-cloudfoundry/src/main/java/org/springframework/boot/cloudfoundry/autoconfigure/actuate/endpoint/servlet/CloudFoundryActuatorAutoConfiguration.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,6 @@ public final class CloudFoundryActuatorAutoConfiguration {
8787

8888
private static final String BASE_PATH = "/cloudfoundryapplication";
8989

90-
@Bean
91-
@ConditionalOnMissingBean
92-
@ConditionalOnAvailableEndpoint
93-
@ConditionalOnBean({ HealthEndpoint.class, HealthEndpointWebExtension.class })
94-
CloudFoundryHealthEndpointWebExtension cloudFoundryHealthEndpointWebExtension(
95-
HealthEndpointWebExtension healthEndpointWebExtension) {
96-
return new CloudFoundryHealthEndpointWebExtension(healthEndpointWebExtension);
97-
}
98-
9990
@Bean
10091
@ConditionalOnMissingBean
10192
@ConditionalOnAvailableEndpoint
@@ -157,6 +148,21 @@ private static CorsConfiguration getCorsConfiguration() {
157148
return corsConfiguration;
158149
}
159150

151+
@Configuration(proxyBeanMethods = false)
152+
@ConditionalOnClass({ HealthEndpoint.class, HealthEndpointWebExtension.class })
153+
static class HealthConfiguration {
154+
155+
@Bean
156+
@ConditionalOnMissingBean
157+
@ConditionalOnAvailableEndpoint
158+
@ConditionalOnBean({ HealthEndpoint.class, HealthEndpointWebExtension.class })
159+
CloudFoundryHealthEndpointWebExtension cloudFoundryHealthEndpointWebExtension(
160+
HealthEndpointWebExtension healthEndpointWebExtension) {
161+
return new CloudFoundryHealthEndpointWebExtension(healthEndpointWebExtension);
162+
}
163+
164+
}
165+
160166
/**
161167
* {@link WebSecurityConfigurer} to tell Spring Security to permit cloudfoundry
162168
* specific paths. The Cloud foundry endpoints are protected by their own security

module/spring-boot-cloudfoundry/src/test/java/org/springframework/boot/cloudfoundry/autoconfigure/actuate/endpoint/servlet/CloudFoundryActuatorAutoConfigurationTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.springframework.boot.servlet.autoconfigure.actuate.web.ServletManagementContextAutoConfiguration;
4848
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
4949
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
50+
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
5051
import org.springframework.boot.webmvc.autoconfigure.DispatcherServletAutoConfiguration;
5152
import org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfiguration;
5253
import org.springframework.context.ApplicationContext;
@@ -92,6 +93,15 @@ class CloudFoundryActuatorAutoConfigurationTests {
9293
ServletManagementContextAutoConfiguration.class, EndpointAutoConfiguration.class,
9394
WebEndpointAutoConfiguration.class, CloudFoundryActuatorAutoConfiguration.class));
9495

96+
@Test
97+
@ClassPathExclusions(packages = "org.springframework.boot.health.actuate.endpoint")
98+
void refreshSucceedsWithoutHealth() {
99+
this.contextRunner
100+
.withPropertyValues("VCAP_APPLICATION:---", "vcap.application.application_id:my-app-id",
101+
"vcap.application.cf_api:https://my-cloud-controller.com")
102+
.run((context) -> assertThat(context).hasNotFailed());
103+
}
104+
95105
@Test
96106
void cloudFoundryPlatformActive() {
97107
this.contextRunner

0 commit comments

Comments
 (0)