Skip to content

Commit

Permalink
Polish "Report friendly error when failing to find AOT initializer"
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Nov 7, 2023
1 parent 8126d26 commit e3210e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,10 @@ private void addAotGeneratedInitializerIfNecessary(List<ApplicationContextInitia
initializers.stream().filter(AotApplicationContextInitializer.class::isInstance).toList());
if (aotInitializers.isEmpty()) {
String initializerClassName = this.mainApplicationClass.getName() + "__ApplicationContextInitializer";
if (!ClassUtils.isPresent(initializerClassName, getClassLoader())) {
throw new IllegalArgumentException(
"You are starting application with AOT mode but not AOT-processed,"
+ " please build your application with AOT first."
+ " Or remove system property 'spring.aot.enabled=true' to run as regular mode.");
}
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1383,8 +1383,8 @@ void shouldReportFriendlyErrorIfAotInitializerNotFound() {
application.setMainApplicationClass(TestSpringApplication.class);
System.setProperty(AotDetector.AOT_ENABLED, "true");
try {
assertThatIllegalArgumentException().isThrownBy(application::run)
.withMessageContaining(AotDetector.AOT_ENABLED);
assertThatIllegalStateException().isThrownBy(application::run)
.withMessageContaining("but AOT processing hasn't happened");
}
finally {
System.clearProperty(AotDetector.AOT_ENABLED);
Expand Down

0 comments on commit e3210e7

Please sign in to comment.