File tree 2 files changed +21
-0
lines changed
spring-boot-project/spring-boot/src
main/java/org/springframework/boot
test/java/org/springframework/boot
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 168
168
* @author Chris Bono
169
169
* @author Moritz Halbritter
170
170
* @author Tadaya Tsuyukubo
171
+ * @author Yanming Zhou
171
172
* @since 1.0.0
172
173
* @see #run(Class, String[])
173
174
* @see #run(Class[], String[])
@@ -436,6 +437,10 @@ private void addAotGeneratedInitializerIfNecessary(List<ApplicationContextInitia
436
437
initializers .stream ().filter (AotApplicationContextInitializer .class ::isInstance ).toList ());
437
438
if (aotInitializers .isEmpty ()) {
438
439
String initializerClassName = this .mainApplicationClass .getName () + "__ApplicationContextInitializer" ;
440
+ Assert .state (ClassUtils .isPresent (initializerClassName , getClassLoader ()),
441
+ "You are starting the application with AOT mode enabled but AOT processing hasn't happened. "
442
+ + "Please build your application with enabled AOT processing first, "
443
+ + "or remove the system property 'spring.aot.enabled' to run the application in regular mode" );
439
444
aotInitializers .add (AotApplicationContextInitializer .forInitializerClasses (initializerClassName ));
440
445
}
441
446
initializers .removeAll (aotInitializers );
Original file line number Diff line number Diff line change 163
163
* @author Sebastien Deleuze
164
164
* @author Moritz Halbritter
165
165
* @author Tadaya Tsuyukubo
166
+ * @author Yanming Zhou
166
167
*/
167
168
@ ExtendWith (OutputCaptureExtension .class )
168
169
class SpringApplicationTests {
@@ -1375,6 +1376,21 @@ void shouldUseAotInitializer() {
1375
1376
}
1376
1377
}
1377
1378
1379
+ @ Test
1380
+ void shouldReportFriendlyErrorIfAotInitializerNotFound () {
1381
+ SpringApplication application = new SpringApplication (TestSpringApplication .class );
1382
+ application .setWebApplicationType (WebApplicationType .NONE );
1383
+ application .setMainApplicationClass (TestSpringApplication .class );
1384
+ System .setProperty (AotDetector .AOT_ENABLED , "true" );
1385
+ try {
1386
+ assertThatIllegalStateException ().isThrownBy (application ::run )
1387
+ .withMessageContaining ("but AOT processing hasn't happened" );
1388
+ }
1389
+ finally {
1390
+ System .clearProperty (AotDetector .AOT_ENABLED );
1391
+ }
1392
+ }
1393
+
1378
1394
@ Test
1379
1395
void fromRunsWithAdditionalSources () {
1380
1396
assertThat (ExampleAdditionalConfig .local .get ()).isNull ();
You can’t perform that action at this time.
0 commit comments