Replace property placeholders in Logback component class names

Closes gh-34336
pull/34503/head
Andy Wilkinson 2 years ago
parent 50da0bce56
commit 31b1c3e8ad

@ -269,7 +269,8 @@ class SpringBootJoranConfigurator extends JoranConfigurator {
private Class<?> loadComponentType(String componentType) { private Class<?> loadComponentType(String componentType) {
try { try {
return ClassUtils.forName(componentType, getClass().getClassLoader()); return ClassUtils.forName(this.modelInterpretationContext.subst(componentType),
getClass().getClassLoader());
} }
catch (Throwable ex) { catch (Throwable ex) {
throw new RuntimeException("Failed to load component type '" + componentType + "'", ex); throw new RuntimeException("Failed to load component type '" + componentType + "'", ex);

@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -190,6 +191,18 @@ class LogbackConfigurationAotContributionTests {
.accepts(generationContext.getRuntimeHints()); .accepts(generationContext.getRuntimeHints());
} }
@Test
void placeholdersInComponentClassAttributeAreReplaced() {
ComponentModel component = new ComponentModel();
component.setClassName("${VARIABLE_CLASS_NAME}");
TestGenerationContext generationContext = applyContribution(component,
(context) -> context.putProperty("VARIABLE_CLASS_NAME", Outer.class.getName()));
assertThat(invokePublicConstructorsAndInspectAndInvokePublicMethodsOf(Outer.class))
.accepts(generationContext.getRuntimeHints());
assertThat(invokePublicConstructorsAndInspectAndInvokePublicMethodsOf(Implementation.class))
.accepts(generationContext.getRuntimeHints());
}
private Predicate<RuntimeHints> invokePublicConstructorsOf(String name) { private Predicate<RuntimeHints> invokePublicConstructorsOf(String name) {
return RuntimeHintsPredicates.reflection() return RuntimeHintsPredicates.reflection()
.onType(TypeReference.of(name)) .onType(TypeReference.of(name))
@ -220,7 +233,13 @@ class LogbackConfigurationAotContributionTests {
} }
private TestGenerationContext applyContribution(Model model) { private TestGenerationContext applyContribution(Model model) {
return this.applyContribution(model, (context) -> {
});
}
private TestGenerationContext applyContribution(Model model, Consumer<LoggerContext> contextCustomizer) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
contextCustomizer.accept(context);
SpringBootJoranConfigurator configurator = new SpringBootJoranConfigurator(null); SpringBootJoranConfigurator configurator = new SpringBootJoranConfigurator(null);
configurator.setContext(context); configurator.setContext(context);
withSystemProperty("spring.aot.processing", "true", () -> configurator.processModel(model)); withSystemProperty("spring.aot.processing", "true", () -> configurator.processModel(model));

Loading…
Cancel
Save