Add runtime hints for VirtualThreadSchedulerMXBean

See gh-43594
This commit is contained in:
Moritz Halbritter 2025-01-13 13:30:38 +01:00
parent 80390305c6
commit 679c0e485c
2 changed files with 20 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2024 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,6 +17,7 @@
package org.springframework.boot.actuate.info; package org.springframework.boot.actuate.info;
import org.springframework.aot.hint.BindingReflectionHintsRegistrar; import org.springframework.aot.hint.BindingReflectionHintsRegistrar;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.boot.actuate.info.Info.Builder; import org.springframework.boot.actuate.info.Info.Builder;
@ -51,6 +52,9 @@ public class ProcessInfoContributor implements InfoContributor {
@Override @Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
this.bindingRegistrar.registerReflectionHints(hints.reflection(), ProcessInfo.class); this.bindingRegistrar.registerReflectionHints(hints.reflection(), ProcessInfo.class);
hints.reflection()
.registerTypeIfPresent(classLoader, "jdk.management.VirtualThreadSchedulerMXBean",
MemberCategory.INVOKE_PUBLIC_METHODS);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2024 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,9 +17,12 @@
package org.springframework.boot.actuate.info; package org.springframework.boot.actuate.info;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.TypeReference;
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
import org.springframework.boot.actuate.info.ProcessInfoContributor.ProcessInfoContributorRuntimeHints; import org.springframework.boot.actuate.info.ProcessInfoContributor.ProcessInfoContributorRuntimeHints;
import org.springframework.boot.info.ProcessInfo; import org.springframework.boot.info.ProcessInfo;
@ -30,6 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link ProcessInfoContributor}. * Tests for {@link ProcessInfoContributor}.
* *
* @author Jonatan Ivanov * @author Jonatan Ivanov
* @author Moritz Halbritter
*/ */
class ProcessInfoContributorTests { class ProcessInfoContributorTests {
@ -52,4 +56,14 @@ class ProcessInfoContributorTests {
.accepts(runtimeHints); .accepts(runtimeHints);
} }
@Test
@EnabledForJreRange(min = JRE.JAVA_24)
void shouldRegisterRuntimeHintsForVirtualThreadSchedulerMXBean() {
RuntimeHints runtimeHints = new RuntimeHints();
new ProcessInfoContributorRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
assertThat(RuntimeHintsPredicates.reflection()
.onType(TypeReference.of("jdk.management.VirtualThreadSchedulerMXBean"))
.withMemberCategories(MemberCategory.INVOKE_PUBLIC_METHODS)).accepts(runtimeHints);
}
} }