Add runtime hints for VirtualThreadSchedulerMXBean
See gh-43594
This commit is contained in:
		
							parent
							
								
									80390305c6
								
							
						
					
					
						commit
						679c0e485c
					
				|  | @ -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"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  | @ -17,6 +17,7 @@ | |||
| package org.springframework.boot.actuate.info; | ||||
| 
 | ||||
| import org.springframework.aot.hint.BindingReflectionHintsRegistrar; | ||||
| import org.springframework.aot.hint.MemberCategory; | ||||
| import org.springframework.aot.hint.RuntimeHints; | ||||
| import org.springframework.aot.hint.RuntimeHintsRegistrar; | ||||
| import org.springframework.boot.actuate.info.Info.Builder; | ||||
|  | @ -51,6 +52,9 @@ public class ProcessInfoContributor implements InfoContributor { | |||
| 		@Override | ||||
| 		public void registerHints(RuntimeHints hints, ClassLoader classLoader) { | ||||
| 			this.bindingRegistrar.registerReflectionHints(hints.reflection(), ProcessInfo.class); | ||||
| 			hints.reflection() | ||||
| 				.registerTypeIfPresent(classLoader, "jdk.management.VirtualThreadSchedulerMXBean", | ||||
| 						MemberCategory.INVOKE_PUBLIC_METHODS); | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
|  |  | |||
|  | @ -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"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  | @ -17,9 +17,12 @@ | |||
| package org.springframework.boot.actuate.info; | ||||
| 
 | ||||
| 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.RuntimeHints; | ||||
| import org.springframework.aot.hint.TypeReference; | ||||
| import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; | ||||
| import org.springframework.boot.actuate.info.ProcessInfoContributor.ProcessInfoContributorRuntimeHints; | ||||
| import org.springframework.boot.info.ProcessInfo; | ||||
|  | @ -30,6 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
|  * Tests for {@link ProcessInfoContributor}. | ||||
|  * | ||||
|  * @author Jonatan Ivanov | ||||
|  * @author Moritz Halbritter | ||||
|  */ | ||||
| class ProcessInfoContributorTests { | ||||
| 
 | ||||
|  | @ -52,4 +56,14 @@ class ProcessInfoContributorTests { | |||
| 			.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); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue