|
|
@ -16,13 +16,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.web.servlet;
|
|
|
|
package org.springframework.boot.web.servlet;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.aot.test.generate.TestGenerationContext;
|
|
|
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
|
|
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
|
|
|
|
|
|
|
import org.springframework.context.ApplicationContextInitializer;
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
|
|
import org.springframework.context.aot.ApplicationContextAotGenerator;
|
|
|
|
|
|
|
|
import org.springframework.context.support.GenericApplicationContext;
|
|
|
|
import org.springframework.core.annotation.AnnotationConfigurationException;
|
|
|
|
import org.springframework.core.annotation.AnnotationConfigurationException;
|
|
|
|
|
|
|
|
import org.springframework.core.test.tools.CompileWithForkedClassLoader;
|
|
|
|
|
|
|
|
import org.springframework.core.test.tools.TestCompiler;
|
|
|
|
|
|
|
|
import org.springframework.javapoet.ClassName;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
@ -121,6 +130,32 @@ class ServletComponentScanRegistrarTests {
|
|
|
|
"com.example.foo", "com.example.bar");
|
|
|
|
"com.example.foo", "com.example.bar");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
@CompileWithForkedClassLoader
|
|
|
|
|
|
|
|
void processAheadOfTimeDoesNotRegisterServletComponentRegisteringPostProcessor() {
|
|
|
|
|
|
|
|
GenericApplicationContext context = new AnnotationConfigApplicationContext();
|
|
|
|
|
|
|
|
context.registerBean(BasePackages.class);
|
|
|
|
|
|
|
|
compile(context, (freshContext) -> {
|
|
|
|
|
|
|
|
freshContext.refresh();
|
|
|
|
|
|
|
|
assertThat(freshContext.getBeansOfType(ServletComponentRegisteringPostProcessor.class)).isEmpty();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
|
|
|
private void compile(GenericApplicationContext context, Consumer<GenericApplicationContext> freshContext) {
|
|
|
|
|
|
|
|
TestGenerationContext generationContext = new TestGenerationContext(
|
|
|
|
|
|
|
|
ClassName.get(getClass().getPackageName(), "TestTarget"));
|
|
|
|
|
|
|
|
ClassName className = new ApplicationContextAotGenerator().processAheadOfTime(context, generationContext);
|
|
|
|
|
|
|
|
generationContext.writeGeneratedContent();
|
|
|
|
|
|
|
|
TestCompiler.forSystem().with(generationContext).compile((compiled) -> {
|
|
|
|
|
|
|
|
GenericApplicationContext freshApplicationContext = new GenericApplicationContext();
|
|
|
|
|
|
|
|
ApplicationContextInitializer<GenericApplicationContext> initializer = compiled
|
|
|
|
|
|
|
|
.getInstance(ApplicationContextInitializer.class, className.toString());
|
|
|
|
|
|
|
|
initializer.initialize(freshApplicationContext);
|
|
|
|
|
|
|
|
freshContext.accept(freshApplicationContext);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@ServletComponentScan({ "com.example.foo", "com.example.bar" })
|
|
|
|
@ServletComponentScan({ "com.example.foo", "com.example.bar" })
|
|
|
|
static class ValuePackages {
|
|
|
|
static class ValuePackages {
|
|
|
|