File tree 2 files changed +23
-0
lines changed
spring-boot-project/spring-boot/src
main/java/org/springframework/boot
test/java/org/springframework/boot
2 files changed +23
-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,12 @@ 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
+ if (!ClassUtils .isPresent (initializerClassName , getClassLoader ())) {
441
+ throw new IllegalArgumentException (
442
+ "You are starting application with AOT mode but not AOT-processed,"
443
+ + " please build your application with AOT first."
444
+ + " Or remove system property 'spring.aot.enabled=true' to run as regular mode." );
445
+ }
439
446
aotInitializers .add (AotApplicationContextInitializer .forInitializerClasses (initializerClassName ));
440
447
}
441
448
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
+ assertThatIllegalArgumentException ().isThrownBy (application ::run )
1387
+ .withMessageContaining (AotDetector .AOT_ENABLED );
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