Skip to content

Commit 13c920b

Browse files
committed
Add AOT support for ReactiveHealthEndpointWebExtension
See gh-31530
1 parent 1f2f624 commit 13c920b

File tree

5 files changed

+87
-34
lines changed

5 files changed

+87
-34
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthEndpointWebExtension.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import java.util.Map;
2222
import java.util.Set;
2323

24-
import org.springframework.aot.hint.RuntimeHints;
25-
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2624
import org.springframework.boot.actuate.endpoint.ApiVersion;
2725
import org.springframework.boot.actuate.endpoint.SecurityContext;
2826
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
@@ -31,9 +29,7 @@
3129
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
3230
import org.springframework.boot.actuate.endpoint.web.WebServerNamespace;
3331
import org.springframework.boot.actuate.endpoint.web.annotation.EndpointWebExtension;
34-
import org.springframework.boot.actuate.health.HealthEndpointWebExtension.HealthEndpointWebExtensionRuntimeHints;
3532
import org.springframework.context.annotation.ImportRuntimeHints;
36-
import org.springframework.context.aot.BindingReflectionHintsRegistrar;
3733

3834
/**
3935
* {@link EndpointWebExtension @EndpointWebExtension} for the {@link HealthEndpoint}.
@@ -116,16 +112,4 @@ protected HealthComponent aggregateContributions(ApiVersion apiVersion, Map<Stri
116112
return getCompositeHealth(apiVersion, contributions, statusAggregator, showComponents, groupNames);
117113
}
118114

119-
static class HealthEndpointWebExtensionRuntimeHints implements RuntimeHintsRegistrar {
120-
121-
private final BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar();
122-
123-
@Override
124-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
125-
this.bindingRegistrar.registerReflectionHints(hints.reflection(), Health.class, SystemHealth.class,
126-
CompositeHealth.class);
127-
}
128-
129-
}
130-
131115
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.health;
18+
19+
import org.springframework.aot.hint.RuntimeHints;
20+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
21+
import org.springframework.context.aot.BindingReflectionHintsRegistrar;
22+
23+
/**
24+
* {@link RuntimeHintsRegistrar} used by {@link HealthEndpointWebExtension} and
25+
* {@link ReactiveHealthEndpointWebExtension}.
26+
*
27+
* @author Moritz Halbritter
28+
*/
29+
class HealthEndpointWebExtensionRuntimeHints implements RuntimeHintsRegistrar {
30+
31+
private final BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar();
32+
33+
@Override
34+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
35+
this.bindingRegistrar.registerReflectionHints(hints.reflection(), Health.class, SystemHealth.class,
36+
CompositeHealth.class);
37+
}
38+
39+
}

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthEndpointWebExtension.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
3333
import org.springframework.boot.actuate.endpoint.web.WebServerNamespace;
3434
import org.springframework.boot.actuate.endpoint.web.annotation.EndpointWebExtension;
35+
import org.springframework.context.annotation.ImportRuntimeHints;
3536

3637
/**
3738
* Reactive {@link EndpointWebExtension @EndpointWebExtension} for the
@@ -43,6 +44,7 @@
4344
* @since 2.0.0
4445
*/
4546
@EndpointWebExtension(endpoint = HealthEndpoint.class)
47+
@ImportRuntimeHints(HealthEndpointWebExtensionRuntimeHints.class)
4648
public class ReactiveHealthEndpointWebExtension
4749
extends HealthEndpointSupport<ReactiveHealthContributor, Mono<? extends HealthComponent>> {
4850

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.health;
18+
19+
import java.util.Set;
20+
21+
import org.junit.jupiter.api.Test;
22+
23+
import org.springframework.aot.hint.MemberCategory;
24+
import org.springframework.aot.hint.RuntimeHints;
25+
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
26+
27+
import static org.assertj.core.api.Assertions.assertThat;
28+
29+
/**
30+
* @author Moritz Halbritter
31+
*/
32+
class HealthEndpointWebExtensionRuntimeHintsTest {
33+
34+
@Test
35+
void shouldRegisterHints() {
36+
RuntimeHints runtimeHints = new RuntimeHints();
37+
new HealthEndpointWebExtensionRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
38+
Set<Class<?>> bindingTypes = Set.of(Health.class, SystemHealth.class, CompositeHealth.class);
39+
for (Class<?> bindingType : bindingTypes) {
40+
assertThat(RuntimeHintsPredicates.reflection().onType(bindingType)
41+
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
42+
.accepts(runtimeHints);
43+
}
44+
}
45+
46+
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthEndpointWebExtensionTests.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,14 @@
1919
import java.time.Duration;
2020
import java.util.Collections;
2121
import java.util.Map;
22-
import java.util.Set;
2322

2423
import org.junit.jupiter.api.Test;
2524

26-
import org.springframework.aot.hint.MemberCategory;
27-
import org.springframework.aot.hint.RuntimeHints;
28-
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
2925
import org.springframework.boot.actuate.endpoint.ApiVersion;
3026
import org.springframework.boot.actuate.endpoint.SecurityContext;
3127
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
3228
import org.springframework.boot.actuate.endpoint.web.WebServerNamespace;
3329
import org.springframework.boot.actuate.health.HealthEndpointSupport.HealthResult;
34-
import org.springframework.boot.actuate.health.HealthEndpointWebExtension.HealthEndpointWebExtensionRuntimeHints;
3530

3631
import static org.assertj.core.api.Assertions.assertThat;
3732
import static org.mockito.Mockito.mock;
@@ -41,7 +36,6 @@
4136
*
4237
* @author Phillip Webb
4338
* @author Scott Frederick
44-
* @author Moritz Halbritter
4539
*/
4640
class HealthEndpointWebExtensionTests extends
4741
HealthEndpointSupportTests<HealthEndpointWebExtension, HealthContributorRegistry, HealthContributor, HealthComponent> {
@@ -87,18 +81,6 @@ void healthWhenPathExistsReturnsHealth() {
8781
assertThat(response.getStatus()).isEqualTo(200);
8882
}
8983

90-
@Test
91-
void shouldRegisterHints() {
92-
RuntimeHints runtimeHints = new RuntimeHints();
93-
new HealthEndpointWebExtensionRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
94-
Set<Class<?>> bindingTypes = Set.of(Health.class, SystemHealth.class, CompositeHealth.class);
95-
for (Class<?> bindingType : bindingTypes) {
96-
assertThat(RuntimeHintsPredicates.reflection().onType(bindingType)
97-
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
98-
.accepts(runtimeHints);
99-
}
100-
}
101-
10284
@Override
10385
protected HealthEndpointWebExtension create(HealthContributorRegistry registry, HealthEndpointGroups groups,
10486
Duration slowIndicatorLoggingThreshold) {

0 commit comments

Comments
 (0)