Merge pull request #38188 from quaff
* pr/38188: Polish "Report friendly error when failing to find AOT initializer" Report friendly error when failing to find AOT initializer Closes gh-38188
This commit is contained in:
@@ -168,6 +168,7 @@ import org.springframework.util.function.ThrowingSupplier;
|
||||
* @author Chris Bono
|
||||
* @author Moritz Halbritter
|
||||
* @author Tadaya Tsuyukubo
|
||||
* @author Yanming Zhou
|
||||
* @since 1.0.0
|
||||
* @see #run(Class, String[])
|
||||
* @see #run(Class[], String[])
|
||||
@@ -436,6 +437,10 @@ public class SpringApplication {
|
||||
initializers.stream().filter(AotApplicationContextInitializer.class::isInstance).toList());
|
||||
if (aotInitializers.isEmpty()) {
|
||||
String initializerClassName = this.mainApplicationClass.getName() + "__ApplicationContextInitializer";
|
||||
Assert.state(ClassUtils.isPresent(initializerClassName, getClassLoader()),
|
||||
"You are starting the application with AOT mode enabled but AOT processing hasn't happened. "
|
||||
+ "Please build your application with enabled AOT processing first, "
|
||||
+ "or remove the system property 'spring.aot.enabled' to run the application in regular mode");
|
||||
aotInitializers.add(AotApplicationContextInitializer.forInitializerClasses(initializerClassName));
|
||||
}
|
||||
initializers.removeAll(aotInitializers);
|
||||
|
||||
@@ -163,6 +163,7 @@ import static org.mockito.Mockito.spy;
|
||||
* @author Sebastien Deleuze
|
||||
* @author Moritz Halbritter
|
||||
* @author Tadaya Tsuyukubo
|
||||
* @author Yanming Zhou
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SpringApplicationTests {
|
||||
@@ -1375,6 +1376,21 @@ class SpringApplicationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReportFriendlyErrorIfAotInitializerNotFound() {
|
||||
SpringApplication application = new SpringApplication(TestSpringApplication.class);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setMainApplicationClass(TestSpringApplication.class);
|
||||
System.setProperty(AotDetector.AOT_ENABLED, "true");
|
||||
try {
|
||||
assertThatIllegalStateException().isThrownBy(application::run)
|
||||
.withMessageContaining("but AOT processing hasn't happened");
|
||||
}
|
||||
finally {
|
||||
System.clearProperty(AotDetector.AOT_ENABLED);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void fromRunsWithAdditionalSources() {
|
||||
assertThat(ExampleAdditionalConfig.local.get()).isNull();
|
||||
|
||||
Reference in New Issue
Block a user