Skip to content

Commit 9b4d920

Browse files
dlwldnjs1009ganeshpc
authored andcommitted
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. See spring-projectsgh-50857 Signed-off-by: Lee JiWon <dlwldnjs1009@gmail.com>
1 parent 93edd16 commit 9b4d920

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfiguration.java

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

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

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

151+
@Configuration(proxyBeanMethods = false)
152+
@ConditionalOnClass(HealthEndpoint.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

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfigurationTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
4949
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
5050
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
51+
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
5152
import org.springframework.context.ApplicationContext;
5253
import org.springframework.http.HttpHeaders;
5354
import org.springframework.http.HttpMethod;
@@ -91,6 +92,15 @@ class CloudFoundryActuatorAutoConfigurationTests {
9192
ServletManagementContextAutoConfiguration.class, EndpointAutoConfiguration.class,
9293
WebEndpointAutoConfiguration.class, CloudFoundryActuatorAutoConfiguration.class));
9394

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

0 commit comments

Comments
 (0)