Generate reflection hints for loggers endpoint's responses
Some of the types that are returned are hidden behind a Map<String, Object> so the operation annotations already been marked as reflective isn't sufficient. This commit uses `@RegisterReflectionForBinding` to register the types that are used as (nested) values in the response maps. Closes gh-32486
This commit is contained in:
parent
180d0edbca
commit
7852c45a77
|
@ -25,10 +25,13 @@ import java.util.NavigableSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
|
||||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||||
import org.springframework.boot.actuate.endpoint.annotation.Selector;
|
import org.springframework.boot.actuate.endpoint.annotation.Selector;
|
||||||
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
|
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
|
||||||
|
import org.springframework.boot.actuate.logging.LoggersEndpoint.GroupLoggerLevels;
|
||||||
|
import org.springframework.boot.actuate.logging.LoggersEndpoint.SingleLoggerLevels;
|
||||||
import org.springframework.boot.logging.LogLevel;
|
import org.springframework.boot.logging.LogLevel;
|
||||||
import org.springframework.boot.logging.LoggerConfiguration;
|
import org.springframework.boot.logging.LoggerConfiguration;
|
||||||
import org.springframework.boot.logging.LoggerGroup;
|
import org.springframework.boot.logging.LoggerGroup;
|
||||||
|
@ -46,6 +49,7 @@ import org.springframework.util.Assert;
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Endpoint(id = "loggers")
|
@Endpoint(id = "loggers")
|
||||||
|
@RegisterReflectionForBinding({ GroupLoggerLevels.class, SingleLoggerLevels.class })
|
||||||
public class LoggersEndpoint {
|
public class LoggersEndpoint {
|
||||||
|
|
||||||
private final LoggingSystem loggingSystem;
|
private final LoggingSystem loggingSystem;
|
||||||
|
|
|
@ -25,6 +25,10 @@ import java.util.Set;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import org.springframework.aot.hint.RuntimeHints;
|
||||||
|
import org.springframework.aot.hint.annotation.ReflectiveRuntimeHintsRegistrar;
|
||||||
|
import org.springframework.aot.hint.predicate.ReflectionHintsPredicates;
|
||||||
|
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||||
import org.springframework.boot.actuate.logging.LoggersEndpoint.GroupLoggerLevels;
|
import org.springframework.boot.actuate.logging.LoggersEndpoint.GroupLoggerLevels;
|
||||||
import org.springframework.boot.actuate.logging.LoggersEndpoint.LoggerLevels;
|
import org.springframework.boot.actuate.logging.LoggersEndpoint.LoggerLevels;
|
||||||
import org.springframework.boot.actuate.logging.LoggersEndpoint.SingleLoggerLevels;
|
import org.springframework.boot.actuate.logging.LoggersEndpoint.SingleLoggerLevels;
|
||||||
|
@ -141,4 +145,19 @@ class LoggersEndpointTests {
|
||||||
then(this.loggingSystem).should().setLogLevel("test.member", null);
|
then(this.loggingSystem).should().setLogLevel("test.member", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void registersRuntimeHintsForClassesSerializedToJson() {
|
||||||
|
RuntimeHints runtimeHints = new RuntimeHints();
|
||||||
|
new ReflectiveRuntimeHintsRegistrar().registerRuntimeHints(runtimeHints, LoggersEndpoint.class);
|
||||||
|
ReflectionHintsPredicates reflection = RuntimeHintsPredicates.reflection();
|
||||||
|
assertThat(reflection.onType(LoggerLevels.class)).accepts(runtimeHints);
|
||||||
|
assertThat(reflection.onMethod(LoggerLevels.class, "getConfiguredLevel")).accepts(runtimeHints);
|
||||||
|
assertThat(reflection.onType(SingleLoggerLevels.class)).accepts(runtimeHints);
|
||||||
|
assertThat(reflection.onMethod(SingleLoggerLevels.class, "getEffectiveLevel")).accepts(runtimeHints);
|
||||||
|
assertThat(reflection.onMethod(SingleLoggerLevels.class, "getConfiguredLevel")).accepts(runtimeHints);
|
||||||
|
assertThat(reflection.onType(GroupLoggerLevels.class)).accepts(runtimeHints);
|
||||||
|
assertThat(reflection.onMethod(GroupLoggerLevels.class, "getMembers")).accepts(runtimeHints);
|
||||||
|
assertThat(reflection.onMethod(GroupLoggerLevels.class, "getConfiguredLevel")).accepts(runtimeHints);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue